Ejemplo de InvalidateFieldChoiceList

En el ejemplo siguiente, un tipo de registro Defect tiene los dos campos product (una referencia al tipo de registro Product) y owner (una referencia a User). Cada tipo de registro Product tiene un campo denominado contributors (una lista de referencia a User).

Con el objeto de que el campo de lista de opciones de owner se actualice cada vez que cambie el valor de Product, puede utilizar el método InvalidateFieldChoiceList, en lugar de utilizar la opción de Recalcular lista de opciones. Consulte el apartado Consideraciones de rendimiento para utilizar enganches para obtener más información.

Por ejemplo, en el tipo de registro Defect, se añade un enganche de valor cambiado para el campo de producto,
  • Perl
    sub product_ValueChanged {
        my($fieldname) = @_;
        # $fieldname as string scalar
        # record type name is Defect
        # field name is product
        # Make sure that the choice list for owner is based on
        # this new value for product.
        $entity->InvalidateFieldChoiceList("owner");
    	}

    y se añade un enganche de lista de opciones para el propietario del campo

    sub owner_ChoiceList 
    {
        my($fieldname) = @_;
        my @choices;
        # $fieldname as string scalar
        # @choices as string array
        # record type name is Defect
        # field name is owner
        # Is the value of product set?  If not, return an empty list.
        my $productFieldInfo = $entity->GetFieldValue("product");
        return @choices unless
        $productFieldInfo->GetValidationStatus() == $CQPerlExt::CQ_KNOWN_VALID;
        return @choices unless $productFieldInfo->GetValue() ne "";
        # Field product is set and valid.
        # Get the list of contributors on this product.
        @choices = $entity->GetFieldValue("product.contributors")
                          ->GetValueAsList();
        return @choices;
    } 
  • VBScript
    Sub product_ValueChanged(fieldname)
      ' fieldname As String
      ' record type name is Defect
      ' field name is product
    	InvalidateFieldChoiceList "owner"
    End Sub

    y se añade un enganche de lista de opciones para el propietario del campo

    Sub owner_ChoiceList(fieldname, choices)
      ' fieldname As String
      ' choices As Object
      ' record type name is Defect
      ' field name is owner
        ' Is the value of product set?  If not, return an empty list.
    	Dim productFieldinfo
    	set productFieldinfo = GetFieldValue("product")
    	if productFieldinfo.GetValidationStatus() <> AD_KNOWN_VALID then exit sub
    	productFieldInfovalue = productFieldinfo.GetValue()
    	if productFieldInfovalue = "" then exit sub
    
        ' Field product is set and valid.
        ' Get the list of contributors on this product.
    	Dim productFieldvalues
    	productFieldvalues = GetFieldValue("product.contributors").GetValueAsList()
    	for each contributor in productFieldvalues
    		choices.AddItem contributor
    	next
    
    End Sub

Cada vez que se inicia una acción, owner_ChoiceList se ejecuta una vez y, cada vez que se cambia product, la lista de opciones owner se marca como no válida. A continuación, la interfaz de usuario solicita la lista de opciones, que fuerza que se vuelva a ejecutar el enganche de lista de opciones.


Feedback