Animesh Das2
Mega Sage

📖🖊...AD_106...

Requirement:

Suppose we have a requirement in ServiceNow IRM (Risk assessment) to configure a custom approval with custom logic that approval should get triggered to approver group members except the submitter who is also part of the approver group.

Here we could consider that the approver group would be the same as the assessor group while creating the Risk assessment project.

 

Solution (Step by step):

Step 1: Search for 'Approval configurations' in the left navigation and open the table 'sn_grc_appr_approval_configuration'.

Step 2: Create a 'Approval Configuration' record with required priority (in case multiple approval configurations are required) and conditions.

Step 3: Create an approval level record from related list of the approval configuration. Lowest level is '1' and can be created up to level '10' out of the box.

Step 4: Create an 'Approval rule' from the related list of the 'Approval level' that we just created in previous step (Multiple rules can be configured if needed). This is the place to configure the actual logic and here we will use scripted approvers with approval required from anyone ('Approver type' = 'Scripted approvers' and 'Approval required from' = 'Anyone')

Step 5: The script for the approval rule can be simple and written as below,

(function execute(parent, users, groups) {
    // parent - GlideRecord object of source table
    // users - Array of approvers, append user sys IDs to this array. Ex: users.push('123');
    // groups - Array of approver groups, append group sys IDs to this array. Ex: groups.push('546');
    var aprGroup = parent.assessor_group.toString(); //get the approver group selected while initiating the Fraud Risk assessment
    var current_assessor = parent.assessor.toString(); //get the assessor selected while assessing the Fraud Risk assessment
 
    //get the users from the assessor group as approvers except the person who is the current assessor.
    var approverGroup = new GlideRecord('sys_user_grmember');
    approverGroup.addEncodedQuery('group=' + aprGroup + '^user!=' + current_assessor);
    approverGroup.query();
    while (approverGroup.next()) {
        users.push(approverGroup.user.toString());
    }
})(parent, users, groups);
 

  

Please note: All these configurations would not be captured in update sets automatically to move across different environments. For code movement, either we need to move the XMLs or capture the updates/configurations in the current update set.

To capture these in the current update set we can use the below script.

var record = new GlideRecord('table_name');
record.get('sys_id_of_record');
//Push the record into the current update set
var forceCapture = new GlideUpdateManager2();
forceCapture.saveRecord(record);

 ...🖋📔😊

 

Thanks, 

Animesh Das

Happy learning and sharing!

You may mark this helpful as well if it helps you.

Version history
Last update:
3 hours ago
Updated by:
Contributors