Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Auto close the parent record when child tasks are closed.

Nagashree5
Tera Contributor

I have a record producer that creates a parent Service desk record and auto creates 3 child general tasks. I would like to prevent from 'Closed Complete' the parent Service desk record until all the child general tasks are 'Closed Complete'. 

Can someone please help with this.

6 REPLIES 6

Hi @VaishnaviShinde ,

 

Im using a workflow here, can this be achieved in workflow?

Also, I want to close the request when the related child tasks are closed. The Request state will be read-only and it will follow the task states.

Thank you in Advance.

@Nagashree5  Yes,

 

Try below

1) Add wait for condition before the end activity and below script in that.

//Query for all tasks to see if they are inactive
var rec = new GlideRecord('sc_task');
rec.addQuery('request_item', current.sys_id);
rec.addQuery('active', true);
rec.query();
if(rec.hasNext()){
answer = false;
}
else{
//Continue
answer = true;
}

 

2) Then add Run script to update the Request and Parent case below is example of Requested Item and request.

var grRitm = new GlideRecord('sc_req_item');
grRitm.addQuery('sys_id', current.sys_id);
grRitm.query();
if (grRitm.next()) {
grRitm.state = '3'; 
grRitm.update();
}

 

var grReq = new GlideRecord('sc_request');
grReq .addQuery('sys_id', current.request);
grReq .query();
if (grReq .next()) {
grReq .state = '3';
grReq .update();
}

 

If my answer solved your issue, please mark my answer as Correct & Helpful