- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
We have a requirement to ensure that if the "Assigned To" user of a change_request is a member of the CAB approval group, that they should not be listed as an approver for the change. We use Change Approval Policies today to handle all the logic/approval requests/etc.
Is there an OOTB way for us to implement this requirement?
Is there a way to script the "Answer" of a change policy decision, so we can check for this condition and remove the user from the Approvers list?
I'd love to avoid customizing the Flow, but that seems like to be our likely path unless the above questions can be answered.
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ZackSmart
Since the OOB Change Approval Policy flow should not be modified, one option is to handle this when the approval record is created.
Create a before insert Business Rule on sysapproval_approver. If the approval is for a Change Request and the approver is also the assigned_to user, mark the approval as No Longer Required.
Example:
(function executeRule(current, previous) {
if (current.getValue('state') !== 'requested') {
return;
}
var changeGR = new GlideRecord('change_request');
if (!changeGR.get(current.getValue('sysapproval'))) {
return;
}
if (changeGR.getValue('assigned_to') !== current.getValue('approver')) {
return;
}
current.setValue('state', 'not_required');
current.setValue(
'comments',
'Approval marked No Longer Required because the approver is the Assigned to user on the Change Request.'
);
})(current, previous);
Suggested Business Rule configuration:
- Table: Approval [sysapproval_approver]
- When: Before
- Insert: True
- Update: False
- Advanced: True
I would test this carefully with the approval policy configuration, particularly where the rule requires all approvers rather than any one approver.
Please mark the response as Helpful or Accept as Solution if it assists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @ZackSmart
Since the OOB Change Approval Policy flow should not be modified, one option is to handle this when the approval record is created.
Create a before insert Business Rule on sysapproval_approver. If the approval is for a Change Request and the approver is also the assigned_to user, mark the approval as No Longer Required.
Example:
(function executeRule(current, previous) {
if (current.getValue('state') !== 'requested') {
return;
}
var changeGR = new GlideRecord('change_request');
if (!changeGR.get(current.getValue('sysapproval'))) {
return;
}
if (changeGR.getValue('assigned_to') !== current.getValue('approver')) {
return;
}
current.setValue('state', 'not_required');
current.setValue(
'comments',
'Approval marked No Longer Required because the approver is the Assigned to user on the Change Request.'
);
})(current, previous);
Suggested Business Rule configuration:
- Table: Approval [sysapproval_approver]
- When: Before
- Insert: True
- Update: False
- Advanced: True
I would test this carefully with the approval policy configuration, particularly where the rule requires all approvers rather than any one approver.
Please mark the response as Helpful or Accept as Solution if it assists.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Thanks, @marianbruma - I added a condition to run when source table == change_request (prevent the BR from running for EVERY new record).
The functionality works, "No Longer Required" is being set correctly, but the "comments" are not being updated in the record (which is a minor/nice-to-have). I tried adding a current.update() to the end but that didnt work either. Suggestions?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago - last edited 2 weeks ago
@ZackSmart , Since the state change is persisting, the Business Rule itself is running correctly. I would not add current.update() to the before-insert rule; values set in a before Business Rule are saved automatically, and calling current.update() can introduce recursion or additional approval processing.
The comments field is a journal field, so its entries are stored separately from normal fields and displayed through the Activity formatter.
First, try setting the value directly:
current.comments =
'Approval marked No Longer Required because the approver is the Assigned To user on the Change Request.';
I would also check the Order of the Business Rule. ServiceNow runs before Business Rules with an order below 1000, then platform engines such as the Approval Engine, followed by before Business Rules with an order of 1000 or higher. An approval-processing engine may be changing the record after your rule executes.
As a test, set the Business Rule order to something such as: 1100
The complete section would be:
if (changeGR.getValue('assigned_to') === current.getValue('approver')) {
current.setValue('state', 'not_required');
current.comments =
'Approval marked No Longer Required because the approver is the Assigned To user on the Change Request.';
}
After testing, check the approval record’s Activity stream rather than expecting the text to appear as a normal stored field value.
Hope this helps! If it does, please mark the response as Helpful or Accept as Solution.