diff --git a/Server-Side Components/Business Rules/Automatically approve when approvers are duplicated./README.md b/Server-Side Components/Business Rules/Automatically approve when approvers are duplicated./README.md new file mode 100644 index 0000000000..0b93e41960 --- /dev/null +++ b/Server-Side Components/Business Rules/Automatically approve when approvers are duplicated./README.md @@ -0,0 +1,13 @@ +In certain scenarios, the same approver might appear multiple times in the approval flow for a Change or Request. This code snippet ensures that if an approver has already approved the request once, any subsequent approval requests assigned to them are automatically marked as approved. + +###Usage Instructions + +Create a new Business Rule on the sysapproval_approver table. +Set the rule to run before insert or update. +Paste the script into the Script field. +Test in a sub-production environment to ensure expected behavior. + +###Notes + +This rule helps reduce redundant approvals and improves efficiency. +Ensure that business logic and compliance requirements allow auto-approvals before deploying. \ No newline at end of file diff --git a/Server-Side Components/Business Rules/Automatically approve when approvers are duplicated./auto-approve.js b/Server-Side Components/Business Rules/Automatically approve when approvers are duplicated./auto-approve.js new file mode 100644 index 0000000000..350651618a --- /dev/null +++ b/Server-Side Components/Business Rules/Automatically approve when approvers are duplicated./auto-approve.js @@ -0,0 +1,14 @@ +(function executeRule(current, previous /*null when async*/ ) { + + var appr = new GlideRecord('sysapproval_approver'); + appr.addQuery('document_id', current.document_id);//look for approval requests for same task + appr.addQuery('approver', current.approver); //same approver exists? + appr.addQuery('state', 'approved'); + appr.addQuery('group','');//ensure this scenario not applied for group type approvals + appr.query(); + if (appr.next()) { + current.state = 'approved'; + current.comments = 'Auto-approved due to duplicate approver at multiple levels.'; + } + +})(current, previous); \ No newline at end of file