상위 레코드의 값 설정을 위한 조치 후크

다음 조치 후크를 상위/하위 링크와 함께 사용하여 상위 레코드와 하위 사이의 State-based 관계를 작성하십시오. 이 후크를 사용하면 모든 하위 레코드가 해당 상태에 있는 경우 상위 레코드를 다음 상태로 이동할 수 있습니다.

주: 이 코드에서는 특정 필드 이름 및 레코드 유형을 가정합니다. 사용자의 환경에서 이 코드를 사용하려면 이 예제에 사용된 일부 필드 이름과 레코드를 변경해야 합니다. ValidateCommit 메소드를 사용할 때 오류 처리에 대한 자세한 정보는 조치 확약 후크 예제를 참조하십시오.

VBScript

Dim SessionObj
Dim ParentID 

' Dimension variables that hold objects
Dim ParentObj 
Dim ChildRefList 
Dim ChildArray 
Dim ChildID 
Dim DefectChildEntityObj 
Dim StateStatus 
Dim SameState 
Dim CurrentState 
Dim ActionJustPerformed 

Dim RetValue 

set SessionObj = GetSession 

ThisID = GetDisplayName 

ActionJustPerformed = GetActionName 

SessionObj.OutputDebugString "action is: "& ActionJustPerformed & vbCrLf

StateStatus = "" 

SameState = 0 

SessionObj.OutputDebugString "current db id is: " & ThisID & vbCrLf 

ParentID = GetFieldValue("parent").GetValue() 

SessionObj.OutputDebugString "parent id is: " & ParentID & vbCrLf 

if ParentID <> "" then 

  set ParentObj=SessionObj.GetEntity("defect", parent_id) 

' you can also call the GetValueAsList method instead of 
' calling GetValue and using the split utility
  ChildRefList=ParentObj.GetFieldValue("children").GetValue 
  ChildArray= split (ChildRefList, vbLf) 

  For Each ChildID In ChildArray 

    set DefectChildEntityObj=SessionObj.GetEntity("Defect", ChildID)

    CurrentState=DefectChildEntityObj.GetFieldValue ("State").GetValue 

    SessionObj.OutputDebugString "StateStatus is: " & StateStatus & vbCrLf 

    SessionObj.OutputDebugString "CurrentState is: " & CurrentState &vbCrLf

    SessionObj.OutputDebugString "SameState is: " & SameState & vbCrLf 

    if StateStatus = "" then 

      StateStatus = CurrentState 

      SameState = 1 

      SessionObj.OutputDebugString "coming to statestatus is null" & vbCrLf 


    elseif StateStatus = CurrentState then 

      SessionObj.OutputDebugString "coming to same state" & vbCrLf 

      SameState = 1 

    else

      SessionObj.OutputDebugString "states are different" & vbCrLf 

      SameState = 0 

    end if
  Next

  if SameState = 1 then 

    SessionObj.OutputDebugString "samestate=1, setting parent state" 

          & vbCrLf

    SessionObj.EditEntity ParentObj, ActionJustPerformed 

    status = ParentObj.Validate 

    if (status <> "") then 
    SessionObj.OutputDebugString "error when updating parent state: "_
     & status & vbCrLf 
      ParentObj.Revert

      exit sub

    end if

    ParentObj.Commit 

  end if

end if

Perl

$SessionObj=$entity->GetSession();

$ThisID=$entity->GetDisplayName();

$ActionJustPerformed=$entity->GetActionName();

$ParentID=$entity->GetFieldValue("parent1")->GetValue();

$StateStatus="";

$SameState=0;


# Rational ClearQuest has a message monitor to display 

# Rational ClearQuest messages and your messages

$SessionObj->OutputDebugString ("perl current db id is: $ThisID\n");

$SessionObj->OutputDebugString ("perl parent id is:  $parent_id\n");


if ($ParentID ne "")  {                    

    $ParentObj = $SessionObj->GetEntity("defect", $ParentID);

# you can also call the GetValueAsList method instead of 
# calling GetValue and using the split utility

    $ChildRefList=$ParentObj->GetFieldValue("children")->GetValue();

    $SessionObj->OutputDebugString ("children are: $ChildRefList\n");

    @ChildArray = split (/\n/,$ChildRefList);   
foreach $ChildID (@ChildArray) {

    $DefectChildEntityObj = $SessionObj->GetEntity("defect", $ChildID);

    $CurrentState=$DefectChildEntityObj->GetFieldValue("State")->
          GetValue();

    $SessionObj->OutputDebugString("perl StateStatus is: $StateStatus\n");

    $SessionObj->OutputDebugString("perl Current Status is: 

          $CurrentStatus\n");

    $SessionObj->OutputDebugString("perl SameState is: $SameState\n");

    if ($StateStatus eq "") {

        $StateStatus = $CurrentState;

        $SameState = 1;

        $SessionObj->OutputDebugString("coming to statestatus is null\n");

    } elsif ($StateStatus eq $CurrentState)  {

        SessionObj->OutputDebugString ("coming to same state\n");

        $SameState = 1;

    } else   {

        $SessionObj->OutputDebugString("states are different\n");

        $SameState = 0;

    }    #nested if statements

} #End foreach Loop


if ($SameState == 1) {

    $SessionObj->OutputDebugString("samestate = 1, setting parent
         state \n");

    $SessionObj->EditEntity($ParentObj, $ActionJustPerformed);

    $status = $ParentObj->Validate();

    if ($status ne "")  {

        $SessionObj->OutputDebugString ("error when updating parent state:
           $status\n");
    $ParentObj->Revert();

    return -1;  # Exit

    }

    $ParentObj->Commit();

}    #end if for ($SameState == 1)

}    #end if for ($ParentID ne "") 

피드백