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.

parent incident should not close when child incident is open

sunnysunny
Kilo Contributor

The requirement is that when we try to close the parent incident while child incidents is open, we should not be able to do that. I wrote BR,before update, but it doesnot work,

please help

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

  var gr = new GlideRecord('incident');

  gr.addQuery('active',true);

  gr.addQuery('parent',current.sys_id);

  gr.query();

  while(gr.next())

  {

  gr.setAbortAction(true);

  }

})(current, previous);

1 ACCEPTED SOLUTION

nope, last row is wrong in your script, sorry missed that.. it should be current.setAbortAction(true); you have gr.setAbortAction(true);


View solution in original post

6 REPLIES 6

darius_koohmare
ServiceNow Employee
ServiceNow Employee

I've seen the same script in the docs, try:


Name: Prevent Closure if Child Task is Active


Type: "Before Update" Business Rule


Table:


Description: Prevents closing a task if any of the task's child tasks are still active.


Parameters:


Script:


var gr = new GlideRecord('task'); 
gr.addQuery('active','true');
gr.addQuery('parent',current.sys_id);
gr.query();
if (gr.next()) {
current.setAbortAction(true); }

In your case, just replace 'task' with 'incident', OR add a run condition for task type = incident.


I want only for incident table, not the task table


replace first like with var gr = new GlideRecord('incident') lie Darius says...




//Göran


Then it will be exactly the same as my client script mentioned above, and it is not working