Change "Change Task" status when Change Request Status Changes

austin_rion
Kilo Contributor

I need to be able to change the Status of any Change Tasks that are in a pending state to "Open" when a change request progresses to the "Scheduled" state. I have created a After, Update business rule with the following script. The rule is running because I get that message I added, however its still not updating the status of the Change task. What am I missing?

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

var ct = new GlideRecord("change_task");

        ct.addQuery("change_request", current.sys_id);

        ct.addQuery("state", "=", -5);

        while (ct.next()) {

                  current.state = "1";

}

})(current, previous);

1 ACCEPTED SOLUTION

nishailame
ServiceNow Employee
ServiceNow Employee

Try This -



You don't want to update the state of current but change_task. also update() was missing.



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


 


        var ct = new GlideRecord("change_task");  


        ct.addQuery("change_request", current.sys_id);  


        ct.addQuery("state", "-5");  


        ct.query();


        while (ct.next()) {  


                    ct.state = "1";


                    ct.update();


        }  


})(current, previous);  



 


Thanks.


PS: Hit like, Helpful, Correct and Endorse, if it answers your question.


View solution in original post

2 REPLIES 2

Chuck Tomasi
Tera Patron

In your while loop, set the state value of the ct record, not current. Your description indicates that you want to update the change task, not 'current' (the change.) You also need to do an update() operation to save the new value to the record.



Example:



while (ct.next()) {


        ct.state = 1;


        ct.update


}


nishailame
ServiceNow Employee
ServiceNow Employee

Try This -



You don't want to update the state of current but change_task. also update() was missing.



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


 


        var ct = new GlideRecord("change_task");  


        ct.addQuery("change_request", current.sys_id);  


        ct.addQuery("state", "-5");  


        ct.query();


        while (ct.next()) {  


                    ct.state = "1";


                    ct.update();


        }  


})(current, previous);  



 


Thanks.


PS: Hit like, Helpful, Correct and Endorse, if it answers your question.