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.

Prevent from closing Parent task until child task is closed.

Jen11
Tera Expert

I have a record producer that creates a parent enhancement task and auto creates 5 child general task. I would like to prevent from 'Closed Complete' the parent task until all the child general task are 'Closed Complete'. 

Can someone please help with this.

1 ACCEPTED SOLUTION

You would need a BR something like below:

find_real_file.png

and your script will look similar to below:

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord('pass child table name');
gr.addQuery('parent', current.sys_id); 
gr.addQuery('state', '!=', 3); 
gr.query();
while(gr.next()){
gs.addErrorMessage('Cannot close Parent with open child');
current.setAbortAction(true); //abort the record
}

})(current, previous);

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

7 REPLIES 7

Prateek kumar
Mega Sage

You would need a business rule, query all the tasks state and abort submission.

https://www.servicenowelite.com/blog/2016/6/11/learn-business-rules

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=c_GlideRecordScopedAPI

https://community.servicenow.com/community?id=community_question&sys_id=8cea0f6ddb5cdbc01dcaf3231f96...


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Thank you.  But i'll need some help with the script.

You would need a BR something like below:

find_real_file.png

and your script will look similar to below:

(function executeRule(current, previous /*null when async*/) {

var gr = new GlideRecord('pass child table name');
gr.addQuery('parent', current.sys_id); 
gr.addQuery('state', '!=', 3); 
gr.query();
while(gr.next()){
gs.addErrorMessage('Cannot close Parent with open child');
current.setAbortAction(true); //abort the record
}

})(current, previous);

 


Please mark my response as correct and helpful if it helped solved your question.
-Thanks

Thank you!