Alternative email addresses lookup on approvals

KB15
Giga Guru

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?

10 REPLIES 10

Carl Fransen1
Tera Guru

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.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

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();
}

Unfortunately, the script modification didn't work. It still rejected processing the email.

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

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();
}