Workflow changes for RITM approvers changes

Rajesh Bandila
Tera Contributor

Hi,

 

I have an below business rule (after update) script and it's working as expected. The script will perform when user changes the assignment group on record it makes existing approvers as "No Longer Required" and added the new assignment group members as an approvers. 

 

My issue is, when the time of script making the old approvers as "No longer Required" the workflow will be moving the "approval group" activity to next activity automatically . My requirement is approval group activity needs to be wait until the new users needs to be approved. 

 

Please find the below workflow for your reference.

RajeshBandila_0-1720448493026.jpeg

 

Business rule script:

(function executeRule(current, previous /*null when async*/) {
   
        // var newGroupSysId = current.u_approver.sys_id.toString();
        var approvalGR = new GlideRecord('sysapproval_approver');
        approvalGR.addQuery('sysapproval', current.sys_id);
        approvalGR.query();
        while (approvalGR.next()) {
            approvalGR.state = 'not_required';
            //approvalGR.deleteRecord();
            approvalGR.update();
        }
       var grMember = new GlideRecord('sys_user_grmember');
        grMember.addQuery('group', newGroupSysId);
        grMember.query();
        while (grMember.next()) {
            var approval = new GlideRecord('sysapproval_approver');
            approval.initialize();
            approval.state = 'requested';
           approval.sysapproval = current.sys_id;
            approval.approver = grMember.user;
            approval.insert();
        }
})(current, previous);

 

Thanks,

Rajesh Bandila

 

1 REPLY 1

Slava Savitsky
Giga Sage

Instead of using a business rule, add a "Run Script" activity at the appropriate place in your Workflow and execute your code from there.