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.

How to cancel open child tasks when change request is closing

sriram7
Tera Contributor

Hi Team,

 

How to cancel open child tasks when change request is closing

 

I have written After Update Business rule, 

 

Condition: current.state == 3 && current.state.changes()

 

Script:

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

    // Add your code here
    abortcanc();

function abortcanc() {
  if (current.sys_id == '') {
    gs.info("Business Rule: Sys_ID is empty. Exiting.");
    return;
  }

  var gr = new GlideRecord('change_task');
  gr.addQuery('parent', current.sys_id);
  gr.query();

  while (gr.next()) {
    if (gr.active == true) {
      gr.state = 4;
      gr.update();
      gs.info("Business Rule: Updated Change Task " + gr.number + " associated with Change Request " + current.number);
    }
  }
 
However code is not working,
 
Can you please help me with this
2 REPLIES 2

Uncle Rob
Kilo Patron

Don't script this.   Flow Designer should be able to do that, codeless.

 

TRIGGER:   On Change Request state changes and state = 3
1 - Look up records on change_task where parent is the trigger record
2 - For each of (1)
3 - Set State = 4


Uncle Rob
Kilo Patron

Also, you no longer need lines like this:

gs.info("Business Rule: Sys_ID is empty. Exiting.");

 

Check out this video I did on the system log context map

 

The ServiceNow system log is invaluable for troubleshooting your instance and solutions. The system log has 2 problems though: volume of transactions, and determining a log entry's origin. Thanks to the new context_map feature, we can solve both problems easily! CHAPTERS 00:00 - The system log is