我经常搜索和搜索,找不到答案。 我想看看ClearQuest中的父记录在所有子记录未关闭之前不应该关闭。 下面是我现在的代码,但未达到目标。帮我 请?
set sessionObj = GetSession
CRdbid = GetFieldValue("dbid").GetValue()
Set entity = sessionObj.GetEntity("CR", CRdbid)
a = entity.GetFieldValue("CR_ID").GetValue()
set querydef = sessionObj.BuildQuery("CR_Child")
querydef.buildfield ("dbid")
querydef.buildfield("ChildCR_ID")
querydef.buildfield("state")
set operator = querydef.BuildFilterOperator(AD_BOOL_OP_AND)
operator.BuildFilter "ChildCR_ID", AD_COMP_OP_LIKE, "a"
operator.BuildFilter "state", AD_COMP_OP_NEQ, "CLOSED"
set resultset = sessionObj.BuildResultSet(querydef)
resultset.execute
if resultset.MoveNext = AD_SUCCESS then
CR_Validation = "Close the child CR's"
End If
答案 0 :(得分:0)
不便。像这样:
$SessionObj=$entity->GetSession();
$ThisID=$entity->GetDisplayName();
$ActionJustPerformed=$entity->GetActionName();
$ParentID=$entity->GetFieldValue("CR_ID")->GetValue();
$closedStatus="CLOSED";
$nonClosed=0;
if ($ParentID ne "") {
$ParentObj = $SessionObj->GetEntity("CR", $ParentID);
# Put the field name instead of 'children'
$ChildRefList=$ParentObj->GetFieldValue("children")->GetValue();
@ChildArray = split (/\n/,$ChildRefList);
foreach $ChildID (@ChildArray) {
$DefectChildEntityObj = $SessionObj->GetEntity("CRChild", $ChildID);
$CurrentState=$DefectChildEntityObj->GetFieldValue("State")->GetValue();
if ($closedStatus ne $CurrentState) {
SessionObj->OutputDebugString ("Got non-closed child!\n");
$nonClosed = 1;
}
}
if ($nonClosed == 0) {
$SessionObj->EditEntity($ParentObj, $ActionJustPerformed);
$status = $ParentObj->Validate();
if ($status ne "") { # error during validation
$SessionObj->OutputDebugString ("error when updating parent state:
$status\n");
$ParentObj->Revert();
return -1; # Exit
}
$ParentObj->Commit(); # no validation errors
}
else{ return -1; # have non-closed children
}
答案 1 :(得分:0)
非常感谢您的回复。 在我从老年人那里接受了良好的教育后,我实际上对我之前的一段代码进行了一些小修改:
Set sessionObj = GetSession
CRdbid = GetFieldValue("dbid").GetValue()
a = GetFieldValue("CR_ID").GetValue()
set querydef = sessionObj.BuildQuery("CR")
querydef.buildfield ("dbid")
querydef.buildfield("CR_ID")
querydef.buildfield("CR_Child.State")
set operator = querydef.BuildFilterOperator(AD_BOOL_OP_AND)
operator.BuildFilter "CR_ID", AD_COMP_OP_LIKE, a
operator.BuildFilter "CR_Child.State", AD_COMP_OP_NEQ, "Closed"
set resultset = sessionObj.BuildResultSet(querydef)
resultset.execute
If resultset.MoveNext = AD_SUCCESS then
CR_Validation = "Close the child CR's"
End If
count = 0
ResultSet.EnableRecordCount
ResultSet.Execute
count = ResultSet.RecordCount
If count > 0 THEN
CR_Validation = "Close the child CR's"
End If
谢谢, 拉吉
答案 2 :(得分:0)
我实际上尝试过你的方式,但仍然看到失败。
但是根据我上面发布的代码,我看到了部分成功。 这意味着查询运行,但在整个数据库上运行以搜索任何未关闭的子记录。 有没有办法可以限制查询只在当前的父记录上运行。?
谢谢, 拉吉