InvalidateFieldChoiceList 예제

다음 예제에서 Defect 레코드 유형에는 product(Product 레코드 유형에 대한 참조) 및 owner(User에 대한 참조)의 두 필드가 있습니다. 각 Product 레코드 유형에는 contributors(User에 대한 참조 목록)라는 필드가 있습니다.

Pruduct에 대한 값이 변경될 때마다 owner 선택사항 목록 필드가 업데이트되도록 하려면, 선택사항 목록 재계산 옵션을 사용하는 대신 InvalidateFieldChoiceList 메소드를 사용할 수 있습니다. 자세한 정보는 후크 사용을 위한 성능 고려사항을 참조하십시오.

예를 들어 Defect 레코드 유형에서 필드 제품에 대한 값 변경 후크를 추가합니다.
  • 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");
    	}

    그리고 필드 소유자에 대한 선택사항 목록 후크를 추가합니다.

    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

    그리고 필드 소유자에 대한 선택사항 목록 후크를 추가합니다.

    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가 한 번 실행되고, product를 변경할 때마다 owner 선택사항 목록이 유효하지 않은 것으로 표시됩니다. 그런 다음 사용자 인터페이스는 선택사항 목록을 요청하여 선택사항 목록 후크가 재실행되도록 합니다.


피드백