InvalidateFieldChoiceList example
In the
following example, a Defect record type has the two fields product
(a
reference to the Product record type) and owner
(a
reference to User). Each Product record type has a field called contributors
(a
reference list to User).
In order for the owner
choice
list field to be updated whenever the value for Product is changed,
you can use the InvalidateFieldChoiceList method,
instead of using the Recalculate Choice List option. See Performance considerations for using hooks for more information.
- 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"); }
and you add a choice list hook for the field owner
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
and you add a choice list hook for the field owner
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
Each time you start an action, owner_ChoiceList is
run once, and every time you change product
,
the owner
choice list is marked as not valid.
The user interface then requests the choice list, which forces the
choice list hook to be re-executed.