0

我搜索和搜索了很多,找不到我的答案。我希望看到 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
4

3 回答 3

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

谢谢,拉吉

于 2013-04-30T09:09:22.803 回答
0

我实际上尝试了您的方式,但仍然看到失败。

但是使用我上面发布的代码,我看到了部分成功。这意味着查询运行,但在整个数据库上运行以搜索任何未关闭的子记录。有没有办法可以限制查询仅在当前父记录上运行。?

谢谢,拉吉

于 2013-05-15T09:48:48.710 回答
0

这可以作为触发器完成,请参阅http://publib.boulder.ibm.com/infocenter/cqhelp/v7r0m0/index.jsp?topic=/com.ibm.rational.clearquest.apiref.doc/r_examples_actsetvalofparent.htm

某事 像这样:

$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
}
于 2013-04-30T06:39:59.480 回答