Alternative email addresses lookup on approvals
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 11:36 AM
It's time I tackle this so I have a question. We have users with different email addresses (due to domain relationships). So when certain users attempt to approve a request, it'll reject them since their primary is not valid. I have a custom secondary email address field and just want to have ServiceNow check if the second email address matches.
I checked the inbound action called "Update Approval Request" and looking at this line:
function validUser() {
if (current.approver == email.from_sys_id)
return true;
Would it just be a simple addition of a condition or would I have to add a query?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 11:45 AM
Hi,
I can't help with the script - but have you thought about using delegations to allow the secondary email address to perform the approvals 'on behalf of'?
Cheers Carl.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 11:58 AM
Yes you just need to update the validUser() function to something like the following. Be sure to update the field name for the secondary email address. Please mark this post as helpful or the correct answer to your question if applicable.
function validUser() {
if (current.approver == email.from_sys_id)
return true;
// check secondary email address
var userRec = new GlideRecord("sys_user");
userRec.get(email.from_sys_id);
if (current.approver == userRec.OTHER-EMAIL-ADDRESS-FIELD-NAME) {
return true;
}
// check if the email is from a delegate of the approver
var g = new GlideRecord("sys_user_delegate");
g.addQuery("user", current.approver.toString());
g.addQuery("delegate", email.from_sys_id);
g.addQuery("approvals", "true");
g.addQuery("starts", "<=", gs.daysAgo(0));
g.addQuery("ends", ">=", gs.daysAgo(0));
g.query();
return g.hasNext();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2018 09:31 PM
Unfortunately, the script modification didn't work. It still rejected processing the email.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-18-2018 05:37 AM
Ah sorry about that, forgot that the out of the box logic won't match a user thus email.from_sys_id won't be populated. Try the following:
function validUser() {
if (current.approver == email.from_sys_id)
return true;
// check secondary email address
if (current.approver.OTHER-EMAIL-ADDRESS-FIELD-NAME == email.from) {
return true;
}
// check if the email is from a delegate of the approver
var g = new GlideRecord("sys_user_delegate");
g.addQuery("user", current.approver.toString());
g.addQuery("delegate", email.from_sys_id);
g.addQuery("approvals", "true");
g.addQuery("starts", "<=", gs.daysAgo(0));
g.addQuery("ends", ">=", gs.daysAgo(0));
g.query();
return g.hasNext();
}