Nel seguente esempio, un tipo di record Defect dispone dei due campi product (un riferimento al tipo di record Product) e owner (un riferimento a User). Ogni tipo di record Product dispone di un campo denominato contributors (un elenco di riferimento a User).
Affinché il campo elenco di selezioni owner venga aggiornato ogni volta che si apporta una modifica al valore di Product, è possibile utilizzare il metodo InvalidateFieldChoiceList invece dell'opzione Calcola nuovamente l'elenco selezioni. Per ulteriori informazioni, consultare Considerazioni sulle prestazioni per l'utilizzo delle funzioni hook.
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"); }
e si aggiunge un hook di elenco selezioni per il campo 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; }
Sub product_ValueChanged(fieldname) ' fieldname As String ' record type name is Defect ' field name is product InvalidateFieldChoiceList "owner" End Sub
e si aggiunge un hook di elenco selezioni per il campo 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
Ogni volta che si avvia un'azione, owner_ChoiceList viene eseguito una sola volta e, ad ogni modifica di product, l'elenco di selezioni owner viene contrassegnato come non valido. L'interfaccia utente richiede l'elenco di selezioni, causando la riesecuzione dell'hook di elenco selezioni.