首页  >> 配置管理  >> IBM Rational ClearQuest / ClearDDTS/TestManager
所有Child到达某一状态, Parent自动到达某一状态
作者 yunshan   查看 818   发表时间 2007/12/23 23:08  【论坛浏览】
最近总结了一下,在Parent/Child模型中,如果所有的Child到达某一状态,则Parent自动到达某一状态。sfqkgnqjk
代码不记得来自哪了,好像是IBM DeveloperWorks,在这里我做了修改。sfqkgnqjk
以Defect为例,配置步骤如下:sfqkgnqjk
1. 在Defect下建立一个字段Parent,类型为REFERENCE_LIST,reference to:Defect,back reference:Childsfqkgnqjk
2. 在Form上从控件面板中拖入2个Parent/Child控件,分别设置属性,关联Parent,Child这两个字段sfqkgnqjk
3. 新建一个Base类型的Action,名称随便,如AutoStatesfqkgnqjk
4. 在AutoState的Notification上添加如下代码:sfqkgnqjk
sfqkgnqjk
  代码:
Dim parent_id sfqkgnqjk
Dim ParentObj sfqkgnqjk
Dim ChildRefList sfqkgnqjk
Dim ChildArray sfqkgnqjk
Dim ChildID sfqkgnqjk
Dim ChildEntityObj sfqkgnqjk
Dim StateStatus sfqkgnqjk
Dim SameState sfqkgnqjk
Dim CurrentState sfqkgnqjk
Dim retvalue sfqkgnqjk
Dim ActionJustPerformed sfqkgnqjk
sfqkgnqjk
set sessionObj = GetSession sfqkgnqjk
ThisID = GetDisplayName sfqkgnqjk
ActionJustPerformed = GetActionName sfqkgnqjk
StateStatus = LookUpStateNamesfqkgnqjk
SameState = 0 sfqkgnqjk
sfqkgnqjk
parent_id = GetFieldValue("Parent").GetValue() sfqkgnqjk
sfqkgnqjk
If parent_id <> "" Then sfqkgnqjk
set ParentObj = sessionobj.GetEntity("Defect", parent_id) sfqkgnqjk
ChildRefList = ParentObj.GetFieldValue("Child").GetValue sfqkgnqjk
ChildArray = split(ChildRefList, vbLf) sfqkgnqjk
sfqkgnqjk
For Each ChildID In ChildArraysfqkgnqjk
If ChildID <> ThisID Thensfqkgnqjk
Set ChildEntityObj = sessionobj.GetEntity("Defect", ChildID) sfqkgnqjk
CurrentState = ChildEntityObj.GetFieldValue("State").GetValue sfqkgnqjk
If StateStatus = CurrentState then sfqkgnqjk
SameState = 1 sfqkgnqjk
Else sfqkgnqjk
SameState = 0sfqkgnqjk
Exit Forsfqkgnqjk
End Ifsfqkgnqjk
End Ifsfqkgnqjk
Next sfqkgnqjk
sfqkgnqjk
If SameState = 1 Then sfqkgnqjk
sessionobj.EditEntity ParentObj, ActionJustPerformed sfqkgnqjk
status = ParentObj.Validate sfqkgnqjk
If status = "" Then sfqkgnqjk
ParentObj.Commitsfqkgnqjk
Elsesfqkgnqjk
ParentObj.Revertsfqkgnqjk
End If sfqkgnqjk
End If sfqkgnqjk
End If
sfqkgnqjk
[ 本帖最后由 yunshan 于 2007-12-23 23:13 编辑 ]

序号 评论者 共有评论 2   【论坛浏览】  【发表评论】 评论时间
1 scmtata 贴一个和这个相关的(推荐一下)
How to make sure the parent record is not closed if its child records are still open

http://www-1.ibm.com/support/docview.wss?uid=swg21146948
2007/12/24 09:19
2 yunshan 我帮tata帖出来:)
How to make sure the parent record is not closed if its child records are still open

Problem
This technote provide sample scripts to make sure that a parent recordin IBM® Rational® ClearQuest® is not closed if its child records arestill open.
Solution
Below are sample scripts in Visual Basic and Perl, to make sure that aparent record in ClearQuest is not closed if its child records arestill open.

Have a validation hook on the Close action to check to see if the children of the parent are all closed,
otherwise invalidate the Closeaction. Then, when a child is closed, the script checks all the otherchildren and if they are all closed, the script closes the parentautomatically.

For verifying the parent's close action, here is the Visual Basic code:

dim oSession, oCmd, oFilter
Set oSession = GetSession
Set oCmd = oSession.BuildQuery("defects")
oCmd.BuildField "parent_record"
oCmd.BuildField "state"
Set oFilter = oCmd.BuildFilterOperator(AD_BOOL_OP_AND)
oFilter.BuildFilter "parent_record", AD_COMP_OP_EQ, GetFieldValue("id").GetValue
Set oData = oSession.BuildResultSet(oCmd)
oData.Execute
Do while oData.MoveNext = AD_SUCCESS
Select Case oData.GetColumnValue(2)
IF not lcase(oData.GetColumnValue(2)) = "closed"
gsr_validation = "Not all defects have been closed"
exit do
end select
Loop

When a child is closed, here is the Visual Basiccode:

Dim oSession, oEntity, sParent, rChildren, i, sName, sStateName, sValid
Set oSession = GetSession
sParent = GetFieldValue("parent_record.id").GetValue
sChildren= GetFieldValue("parent_record.defect_children").GetValueAsList
continue = false
foundOpen = false
foundClosed = false
For each i in sChildren
Set oEntity = oSession.GetEntity("defects",i)
Set oState = oEntity.GetFieldValue("state")
If oState.GetValueStatus = AD_HAS_VALUE then
Select Case lcase(oState.GetValue)
Case "closed"
foundClosed = true
Case Else
foundOpen = true
End Select
End if
Next set oState = nothing
continue = (Not foundOpen) And (foundClosed)

if continue = true then
Set oEntity = oSession.GetEntity("defects",sParent)
oSession.EditEntity oEntity, "Close"
sValid = oEntity.Validate
If sValid = "" then
oEntity.Commit
else
'Handle the error
end if
end if

Set oEntity = nothing
Set oSession = Nothing



Here is the Perl Script:

This script would be in the validation of an action.

# Get the field object for the list of children
$fObjChildrenList = $entity->GetFieldValue("ChildrenDefects");
# Check if there are any children
if($fObjChildrenList->GetValueStatus() == $CQPerlExt::CQ_HAS_VALUE){
# if there are....
# init result for later
$result = "";
# Get the actual list of children (this will return a list of the unique id (id)
$children = $fObjChildrenList->GetValueAsList();
# Break the list into an array
@childrenList = @$children;
# need session object to get entity records (children)
$oSess = $entity->GetSession();
# go through the list of children, if any are not in COMPLETE state add to error message
foreach $child(@childrenList){
# Get the entity (record) of the current childr
$eChild = $oSess->GetEntity("Defect", $child);
# check the state, if not complete add to error message
unless($eChild->GetFieldValue("State")->GetValue() eq "Complete"){
$result .= "$child, ";
}
}
}
# if result is empty there were no children OR all are COMPLETE
unless($result eq ""){
# if result is NOT empty then set error message for validation failure, including the children that are not COMPLETE
$result = "Following Children Not in Complete State - " . $result . " This record can not be moved to Work Complete";
}
return $result;


DISCLAIMER:

All source code and/or binaries attached to this document are referredto here as "the Program". IBM is not providing program services of anykind for the Program. IBM is providing the Program on an "AS IS" basiswithout warranty of any kind. IBM WILL NOT BE LIABLE FOR ANY ACTUAL,DIRECT, SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMICCONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF IBM,OR ITS RESELLER, HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
2007/12/24 09:29
 共有评论数 2  每页显示 10
页码 1/1  |<  <<   1   >>  >|