Manually re-assign a new approver on the approval plans/ change approver on PR.

Ayushi Saxena
Tera Contributor
There is approver plan custom table. While changing the approver from approval list on a approver plan custom table in ServiceNow, approver details are not getting reflected in related list approver column which is redirecting to the sysapproval_approver table.
 
3 ACCEPTED SOLUTIONS

shantanu_patel8
Mega Guru

Hi @Ayushi Saxena  ,

 

How are the customer table and sysapproval_approver table related. 

 

If you are changing something in your custom table and want the changes to reflect in sysapprover_approval table then the best way would be:

1. write a after business rule in your custom table.

2. Condition when approver changes

3. Write script to query the sysapprover_approval table and update the approver field.

 

Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂

-Shantanu

View solution in original post

Without getting into much detail in the code, you are missing the appr.query(); before the while loop

View solution in original post

@Ayushi Saxena You are missing the appr.query() before the while(appr.next()).

 

Try it. hopefully your issue will be resolved.

 

Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂

-Shantanu

View solution in original post

4 REPLIES 4

shantanu_patel8
Mega Guru

Hi @Ayushi Saxena  ,

 

How are the customer table and sysapproval_approver table related. 

 

If you are changing something in your custom table and want the changes to reflect in sysapprover_approval table then the best way would be:

1. write a after business rule in your custom table.

2. Condition when approver changes

3. Write script to query the sysapprover_approval table and update the approver field.

 

Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂

-Shantanu

yes I have written After Updated BR On "sn_shop_approval_plan" table. Code is working but everytime getting no match found. Not sure what is wrong with the query

 

 

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

    if (current.approver_list.toString() != previous.approver_list.toString()) {
        gs.info('[ayu] Approver changed from ' + previous.approver_list + ' to ' + current.approver_list);

        var appr = new GlideRecord('sysapproval_approver');
        appr.addQuery('sysapproval', current.sys_id);
        //appr.addQuery('approver', previous.approver_list);
        appr.addQuery('state', 'requested');
        gs.info('[ayu] Querying sysapproval_approver for task: ' + current.sys_id);
        gs.info('[ayu] Querying sysapproval_approver for previous approver: ' + previous.approver_list);
        var found = false;
        while (appr.next()) {
            appr.approver = current.approver_list;
            appr.update();
            gs.info('[ayu] Updated approver to: ' + appr.approver);
            found = true;
        }

        if (!found) {
            gs.info('[ayu] No matching pending approval record found.');
        }

    } else {
        gs.info('[ayu] Approver did not change — no action taken.');
    }

})(current, previous);

Without getting into much detail in the code, you are missing the appr.query(); before the while loop

@Ayushi Saxena You are missing the appr.query() before the while(appr.next()).

 

Try it. hopefully your issue will be resolved.

 

Please mark the answer helpful and correct if it helps the issue. Happy scripting 🙂

-Shantanu