Change CTASK status when Change Request state changes

Vishnu V Reddy
Tera Contributor

Hi, my requirement is put the CTASKs in Pending state until the CR moves to waiting for deploy. Once CR is in waiting for deploy, CTASK should be in OPEN state. I have modified the subflow of CTASKS to be in pending when they are opened, but can't figure out how to do the rest.

7 REPLIES 7

Pradeep Sharma
ServiceNow Employee
ServiceNow Employee

Hello Vishnu,



You can have a BEFORE business rule on change task and update the status based on change request table. Also an After business rule on change request table to update related change task depending on the conditions you have mentioned.



Please let me know if you have any questions.


Pradeep, can you help me with the script? Just a rough plot


CHANGE TASK TABLE:


chg= new GlideRecord('change_request');


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


if(!chg.hasNext()){


if(chg.state == '' ||chg.state == '' ){ //Change state Value


current.state = 4; //Task state value


}


if(chg.state == '' ||chg.state == '' ){ //Change state Value


current.state = 4; //Task state value


}


}




CHNAGE TABLE:


chg= new GlideRecord('change_task');


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


if(!chg.hasNext()){


if(current.state == '' ||current.state == '' ){ //Change state Value


chg.state = 4; //Task state value


}


if(current.state == '' ||current.state == '' ){ //Change state Value


chg.state = 4; //Task state value


}


chg.update();


}


Hello Vishnu,



Sample script below to be created on Change Request table(AFTER BR).


var gr = new GlideRecord('change_task');


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


gr.query();


if(gr.next()){


if(current.state = 'PASS CHOICE VALUE OF WAITING FOR DEPLOY')


{


gr.state = '1';


}


if(current.state = 'PASS CHOCIE VALUE OF STATE FOR WHICH YOU NEED CHANGE TASK TO BE PENDING')


{


gr.state = "UPDATE CHOICE VALUE OF CHANGE TASK HERE I.E PENDING";


}



}


gr.update();