Utilisez le crochet d'action ci-après dans une liaison parent-enfant pour créer une relation fondée sur l'état entre un enregistrement parent et ses enfants. This hook moves the parent record to the next state if all the children are in that state.
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 "ID DB en cours : " & 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 : " & 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
$SessionObj=$entity->GetSession();
$ThisID=$entity->GetDisplayName();
$ActionJustPerformed=$entity->GetActionName();
$ParentID=$entity->GetFieldValue("parent1")->GetValue();
$StateStatus="";
$SameState=0;
# Rational ClearQuest dispose d'un moniteur
# permettant d'afficher les messages de Rational ClearQuest
# et les vôtres
$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 "")