Approval Delegation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2023 02:39 PM
I am trying to make a business rule to allow an assignment group the ability to add and remove delegates from a manager user record. Once the delegate is inserted, updated, or deleted it should either show the newly inserted/updated delegate as the approver, and resend the needed approval emails. Or if delegate(s) are deleted it should revert to the 'requested_for' user's manager. The manager is also the original approver. The script below is what I have so far, and while it seems to change the approver to the new delegate, it doesn't seem to work on the updated delegate, and more importantly does not revert to the manager/original approver once the delegate(s) are deleted.
A few things to note, would be that I have created a dictionary entry (column) on the 'sysapproval_approver' table named 'u_original_approver' as a means to store the user's manager as the way to revert it back if delegates are deleted. Furthermore, I have the business rule working on the 'sys_user_delegate' table, queueing up an event of 'approval.delegate.changed' which fires off a notification to approve the request which runs off the 'sysapproval_approver' table.
Any help would be appreciated, and if you need any clarification please let me know. Thank you.
(function executeRule(current, previous /*null when async*/) {
//Checks if the current user has the required roles
if (!gs.hasRole('advocate_tier_1') && !gs.hasRole('admin')) {
return;
}
//Defines a variable to store the delegate
var delegate = '';
if (current.operation() != 'delete') {
delegate = current.delegate;
} else {
delegate = previous.delegate;
}
//Queries the active approvals where the approver is the user whose delegate has been updated
var approvalGR = new GlideRecord('sysapproval_approver');
approvalGR.addQuery('state', 'requested');
approvalGR.addQuery('approver', current.user);
approvalGR.query();
//Loops through the active approvals
while (approvalGR.next()) {
//Gets the related RITM record
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(approvalGR.document_id)) {
//Gets the 'requested_for' user and user's manager
var requestedForUserGR = new GlideRecord('sys_user');
if (requestedForUserGR.get(ritmGR.requested_for)) {
var manager = requestedForUserGR.manager;
}
}
//If a new delegate is added or the delegate is updated, it reassigns the approval to the new delegate and stores the original approver
if (current.operation() != 'delete' && delegate != '') {
approvalGR.u_original_approver = manager;
approvalGR.approver = delegate;
//If the delegate is deleted or the delegate is updated, it reverts the approver back to the original approver
} else {
approvalGR.approver = manager;
approvalGR.u_original_approver = ''; // Clear the original approver field after reverting
}
approvalGR.update();
//Sends a notification about the approval task
gs.eventQueue('approval.delegate.changed', approvalGR, delegate, current.user);
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2023 02:50 PM
My first thought is, Why are you going thru this? The system automatically sends an email to the approver and any delegate that is set to receive approval notifications. If all you want is to prevent the original user from getting the email it feels like there is a getter way then trying to mess with the approval records.
If you just want to retrigger the notification when the delegates are updated, then this code will do that where current is the approval record. We use the below in a UI action so you can send the notification again.
(function(){
var task = current.sysapproval.sys_class_name;
var event = "approval.inserted";
if (task == 'sc_request')
event = "request.approval.inserted";
else if (task == 'sc_task')
event = "sc_task.approval.inserted";
else if (task == 'std_change_proposal')
event = "std_change_proposal.approval.inserted";
gs.eventQueue(event, current, gs.getUserID(), gs.getUserName());
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2023 03:05 PM
The reason I was going about it this way is because many people tend not to set up delegates, and then when a request arises where they are unable to approve it, some other user is calling asking to switch the delegates. And rather than put it on our engineers to change the delegates we are having our Help Desk make the call, and giving them the ability to change manager delegation.
In regards to your resolution, is this more of a manual 'reprocess notification' button? Because if so this might work also. They could add a delegate, and then reprocess the approvals?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2023 03:28 PM
We have the same issue with delegates. We created a cat item to help them since telling people to go to there profile and add them was not working at all. But people don't fill the cat item out either so....
When we have people call into the SD desperate to have something approved the SD updates the approval record directly and then selects the button to Send Notification. Then they tell the user the approval record has been update and to go pester the new person. Also to be clear we have only like 2 maybe 3 people allowed to do this since the SD person has to verify they are at least having someone at the same level approve the request. i.e. director to director, manager to manager. So we created a group and gave it the approval_admin role I think it was.
You could have it happen automagically run the code when a delegate is inserted/updated/deleted if you want. We went with the manual option because the automated one had to many what-if's.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2023 03:32 PM
Ah ok, yea I guess it was from upper mgmt. that they wanted the whole thing automated. So a delegate change would trigger everything, and delegate removal would revert to the previous manager.