0

I searched and searched a lot and couldn't find my answer. I want to see that a parent record in ClearQuest should not get closed before all of its child records aren't closed. Below is the code that I am upto now., but failing to meet the objective. Help me please?

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
Sneftel
  • 40,271
  • 12
  • 71
  • 104
Rajkgdr
  • 1
  • 1

3 Answers3

0

this may be done as a trigger, see http://publib.boulder.ibm.com/infocenter/cqhelp/v7r0m0/index.jsp?topic=/com.ibm.rational.clearquest.apiref.doc/r_examples_actsetvalofparent.htm

smth. like this:

$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
}
lizard
  • 1
0

Thanks much for your response. I actually did a small modification to my earlier piece of code after I got some good education from seniors:

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

Thanks, Raj

Rajkgdr
  • 1
  • 1
0

I actually tried your way, but still see failures.

but with the code that I have posted above, I see a partial success though. Meaning the query runs, but runs on the entire database to search for any not closed Child records. Is there a way I can limit the query to run only on the current Parent record.?

Thanks, Raj

Rajkgdr
  • 1
  • 1