How to Approval synchronized between Change Request and CTask.

Servicenow de11
Tera Contributor

Hello,

 

Our Requirement is In change request approval field must be synchronized to Ctask.

Ex: In change request if the approval field changed to approved , then Ctask also approval field will change to approved.Attached screenshot.

I have tried one after insert business rule for change_task table but its not working.

Can anyone help how to achieve this requirement.

 

(function executeRule(current, previous /*null when async*/) {
 
    var gr = new GlideRecord('change_request');
    gr.addQuery('number', current.change_request);
    getRITM.query();
    if (gr.next()) {
        current.approval = gr.approval;
        current.update();
current.setWorkflow(false);
}
 
})(current, previous);

 

Thanks in advance

2 ACCEPTED SOLUTIONS

Harish KM
Kilo Patron
Kilo Patron

Hi @Servicenow de11 I have corrected your script.

Your Business rule must be on change request table with after update checked

script:

  var chgTask = new GlideRecord('change_task'); //change task table
    chgTask.addQuery('change_request', current.sys_id); // change request task matches with parent
    chgTask.query();
    if (chgTask.next()) {
        chgTask.approval = current.approval; // update approval state
        chgTask.update();
        //current.setWorkflow(false);
    }
Regards
Harish

View solution in original post

Hi @Servicenow de11 change if condition to while condition like below

 

if (chgTask.next()) { // change this to

while(chgTask.next()

Regards
Harish

View solution in original post

4 REPLIES 4

Harish KM
Kilo Patron
Kilo Patron

Hi @Servicenow de11 I have corrected your script.

Your Business rule must be on change request table with after update checked

script:

  var chgTask = new GlideRecord('change_task'); //change task table
    chgTask.addQuery('change_request', current.sys_id); // change request task matches with parent
    chgTask.query();
    if (chgTask.next()) {
        chgTask.approval = current.approval; // update approval state
        chgTask.update();
        //current.setWorkflow(false);
    }
Regards
Harish

Hi Harish,

 

Thanks for the script, its working now.

Hi Harish,

 

Script is working for only one CTask created. If we create more than one CTask the given is not working.

Servicenowde11_0-1706855809793.png

Can you please let me know the script  for all Ctasks approvals updated.

Hi @Servicenow de11 change if condition to while condition like below

 

if (chgTask.next()) { // change this to

while(chgTask.next()

Regards
Harish