all change tasks states update to closed skipped if change request state is changed to closed skipped.

Jan-Z
Giga Expert

I have a requirement where if a change request is "closed skipped" meaning the state is put into "closed skipped"

all of the change tasks (usually around 7) associated with the change request are to have their state set to "closed skipped" as well.   I am not a coder and the business rule I created is not working.  Any help would be welcome. 

thanks. 

Business rule.  

Table = change_request

When to run:

when= after

insert and update are checked

condition:  state changes to "closed skipped". 

Advanced :

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

// Add your code here

var gr = new GlideRecord('change_task');


gr.get(current.change_task);

 

gr.state = 7; //this needs to be the value of your closed skipped choice


gr.update();


})(current, previous);

 

 

1 ACCEPTED SOLUTION

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Here you go.

 

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

// Add your code here

var gr = new GlideRecord('change_task');
gr.addQuery('change_request',current.sys_id);
gr.addQuery('state', '!=', 7);
gr.query();
while(gr.next())
{

gr.state = 7; //this needs to be the value of your closed skipped choice
gr.update();
}


})(current, previous);

 

-Pradeep Sharma

View solution in original post

3 REPLIES 3

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Here you go.

 

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

// Add your code here

var gr = new GlideRecord('change_task');
gr.addQuery('change_request',current.sys_id);
gr.addQuery('state', '!=', 7);
gr.query();
while(gr.next())
{

gr.state = 7; //this needs to be the value of your closed skipped choice
gr.update();
}


})(current, previous);

 

-Pradeep Sharma

Mark Stanger
Giga Sage

Here you go.  You'll want this to run in an 'after' 'update/insert' business rule.

(function executeRule(current, previous /*null when async*/) {
    // Query for associated change tasks
    var gr = new GlideRecord('change_task');
    gr.addQuery('change_request', current.sys_id);
    gr.addActiveQuery();
    gr.query();
    while (gr.next()) {
        gr.state = 7; //this needs to be the value of your closed skipped choice
        gr.work_notes = 'Change task closed due to closure of Change request.');
        gr.update();
    }
})(current, previous);

Please mark this answer as correct if I've answered your question.  Thanks!

Jan-Z
Giga Expert

Thank you both.  So glad to see your back Mark!


How do I mark you both as correct??