加入收藏 | 设为首页 | Life家族 | SCMLife | RMLife | PMLife | SQALife | TESTLife | 企业VIP专区 | 中文化荣誉殿堂
 
发新话题
打印

[推荐] 所有Child到达某一状态, Parent自动到达某一状态( 此文章被查看:1109次,被回复:2篇!! )

本主题被作者加入到个人文集中

所有Child到达某一状态, Parent自动到达某一状态

最近总结了一下,在Parent/Child模型中,如果所有的Child到达某一状态,则Parent自动到达某一状态。
代码不记得来自哪了,好像是IBM DeveloperWorks,在这里我做了修改。
以Defect为例,配置步骤如下:
1. 在Defect下建立一个字段Parent,类型为REFERENCE_LIST,reference to:Defect,back reference:Child
2. 在Form上从控件面板中拖入2个Parent/Child控件,分别设置属性,关联Parent,Child这两个字段
3. 新建一个Base类型的Action,名称随便,如AutoState
4. 在AutoState的Notification上添加如下代码:
复制内容到剪贴板
代码:
        Dim parent_id
        Dim ParentObj
        Dim ChildRefList
        Dim ChildArray
        Dim ChildID
        Dim ChildEntityObj
        Dim StateStatus
        Dim SameState
        Dim CurrentState
        Dim retvalue
        Dim ActionJustPerformed

        set sessionObj = GetSession
        ThisID = GetDisplayName
        ActionJustPerformed = GetActionName
        StateStatus = LookUpStateName
        SameState = 0

        parent_id = GetFieldValue("Parent").GetValue()

        If parent_id <> "" Then
                set ParentObj = sessionobj.GetEntity("Defect", parent_id)
                ChildRefList = ParentObj.GetFieldValue("Child").GetValue
                ChildArray = split(ChildRefList, vbLf)

                For Each ChildID In ChildArray
                  If ChildID <> ThisID Then
                    Set ChildEntityObj = sessionobj.GetEntity("Defect", ChildID)
                    CurrentState = ChildEntityObj.GetFieldValue("State").GetValue
                    If StateStatus = CurrentState then
                        SameState = 1
                    Else
                        SameState = 0
                        Exit For
                    End If
                  End If
                Next

                If SameState = 1 Then
                        sessionobj.EditEntity ParentObj, ActionJustPerformed
                        status = ParentObj.Validate
                        If status = "" Then
                                ParentObj.Commit
                        Else
                                ParentObj.Revert
                        End If
                End If
        End If
[ 本帖最后由 yunshan 于 2007-12-23 23:13 编辑 ]



© 本文为 yunshanSCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

贴一个和这个相关的(推荐一下)

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



© 本文为 scmtataSCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员
勇敢的心

TOP

我帮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.



© 本文为 yunshanSCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

发新话题