Approver delegate emails

Chad Hall
Giga Guru

I've built a way to notify approver delegates whenever their delegator has a new approval request, so I thought I would share it here. I used another post that did something very similar and just modified it to do what I wanted. I know the delegation option lets you specify someone as an Approval delegate but that by itself doesn't notify them when they have a new approval request. There is also the option to CC Notifications but that sends them every single notification intended for the delegator and not strictly the approval notifications. There wasn't a middle ground. I needed a way to only send approval delegates the approval notifications. Here's what I did:

1. Create a new email script with the following code:

// Add delegates to an approval email

var delegate = new GlideRecord('sys_user_delegate');

delegate.addQuery('user',current.approver.sys_id);

delegate.addQuery('starts','<=',gs.nowNoTZ());

delegate.addQuery('ends','>=',gs.nowNoTZ());

delegate.addQuery('approvals','true');

delegate.query();

while (delegate.next()) {

  // get the email address of the delegate if they have notification enabled

      var usr = new GlideRecord('sys_user');

      usr.addQuery('sys_id',delegate.delegate);

      usr.addQuery('notification','2');

      usr.addQuery('active','true');

      usr.query();

      while (usr.next()) {

  // add the delegate's email to the "cc" list

          email.addAddress("cc", usr.email, usr.name);

      }

  }

2. Reference this script within the email templates used by your approval notifications, like this:

        ${mail_script:approval_delegate_cc}

This will allow your delegates to get approval emails for the delegator without getting all the noise of the delegator's other emails. It does not require any special configuration within the delegation record other than enabling the Approvals option. Additionally, if the delegate disables their own email notifications or if the delegate is deactivated this email will be suppressed. This feature will come in handy for requester users who do not have full UI access to perform approvals but are setup as delegates. This way they get emails for the approvals and can approve via email.

1 ACCEPTED SOLUTION

jeffsalisbury
Kilo Expert

This was exactly what we needed - thank you so much for sharing! It worked like a champ.


View solution in original post

6 REPLIES 6

jeffsalisbury
Kilo Expert

This was exactly what we needed - thank you so much for sharing! It worked like a champ.


fibssy
Tera Guru

THhis is awesome. Thank you very much for sharing. Exactly what I needed

TEdwards
Kilo Sage

I am having a problem with this and am not quite sure what I am doing wrong. I have added the script to email scripts, referenced the script in the email template, and configured my test delegates' approval option, yet no email is sent unless I check CC Notifications, and then they receive all of the notifications. Any idea what I might have missed?

If you would please post your mail script and the email template here so I can look it over.