InvalidateFieldChoiceList 例

以下の例では、障害レコード タイプには、product (製品レコード タイプを参照) と owner (ユーザーを参照) の 2 つのフィールドがあります。製品レコード タイプにはそれぞれ、contributors (ユーザーへの参照リスト) と呼ばれるフィールドがあります。

製品の値が変更されるたびに owner 選択リスト フィールドが更新されるためには、[選択リストを再計算] オプションではなく、InvalidateFieldChoiceList メソッドを使用します。詳しくは、フックの使用に関するパフォーマンスの考慮 を参照してください。

例えば、障害レコード タイプでは、フィールド product の変更された値フックを追加します。
  • 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

アクションを開始するたびに、owner_ChoiceList が 1 度実行され、product を変更するたびに owner 選択リストが無効とマークされます。その後、ユーザー インターフェイスにより選択リストが要求され、選択リスト フックの再実行が強制されます。


フィードバック