
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 04:35 PM
I have an issue that I'm sure isn't unique, but after reading quite a few posts here I'm not sure if there is a good, system wide way to check a custom field on sys_user for an email address related to a new inbound message.
We have a field on sys_user "u_alternate_email" that is used for some users that we have who technically belong to two different companies and have two different email addresses. Originally there were two separate user accounts, but that created a lot of confusion for these users, and related records were split between the two, so it was hard to see everything related to that person in one place. There were also issues with SSO authentication with two different accounts.
Now, in a few cases, we have users that are have sent inbound mail to the instance with their alternate email address, but the system ignores it because it's not in the OOB email field. Is there a way that we can globally define a business rule for inbound email that would associate to the user's record if either email or u_alternate_email is the same as the sender's address?
I've seen examples where something similar has been done in individual inbound action scripts, but I'd like to avoid updating potentially 100s of specific inbound action scripts to account for all possible cases where this might occur.
Any thoughts or suggestions are appreciated!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 07:14 PM
This problem was solved several years ago in this blog post by Brian Dailey:
- https://community.servicenow.com/community?id=community_blog&sys_id=5a5da629dbd0dbc01dcaf3231f961937
The solution is a before insert/update business rule on the sys_email table. Brian's original solution was based on using cmn_notif_device to obtain the alternate email address. We modified it to use an alternate email address in sys_user, just as you are doing.
Here is the code for our business rule.
(function executeRule(current, previous /*null when async*/) { // Update received email based on match of alternate email. // Based on the following blog post by Brian Dailey: // https://community.servicenow.com/community?id=community_blog&sys_id=5a5da629dbd0dbc01dcaf3231f961937 var myname = '<<name of this business rule>>'; // If current.user_id is set then the OOB code must have matched on email if (current.user_id) return; var sender = current.getValue('user'); if (!sender) { gs.log(myname + ': No sender address', myname); return; } // Reply To field is used OOB only for Sent emails // So use this field to save the sender's email address current.reply_to = sender; matchUserByAltEmail(); if (!current.user_id) { gs.log(myname + ': No user found for address: ' + current.user, myname); } function matchUserByAltEmail(){ // Match on u_alternate_email var grUser = new GlideRecord('sys_user'); if (sender && grUser.get('u_alternate_email', sender)) { current.user_id = grUser.getUniqueValue(); current.user = grUser.getUniqueValue(); gs.log('Email ' + current.sys_id + ' matched ' + sender + ' to u_alternate_email for ' + grUser.name, myname); } } })(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-15-2020 05:11 PM
How about you write an insert before Business rule and check if the email is received from alternate email address and set the user id accordingly.
Please mark my response as correct answer and helpful if it helped solved your question.
-Best Regards
Prateek kumar
Please mark my response as correct and helpful if it helped solved your question.
-Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 06:49 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-17-2020 07:14 PM
This problem was solved several years ago in this blog post by Brian Dailey:
- https://community.servicenow.com/community?id=community_blog&sys_id=5a5da629dbd0dbc01dcaf3231f961937
The solution is a before insert/update business rule on the sys_email table. Brian's original solution was based on using cmn_notif_device to obtain the alternate email address. We modified it to use an alternate email address in sys_user, just as you are doing.
Here is the code for our business rule.
(function executeRule(current, previous /*null when async*/) { // Update received email based on match of alternate email. // Based on the following blog post by Brian Dailey: // https://community.servicenow.com/community?id=community_blog&sys_id=5a5da629dbd0dbc01dcaf3231f961937 var myname = '<<name of this business rule>>'; // If current.user_id is set then the OOB code must have matched on email if (current.user_id) return; var sender = current.getValue('user'); if (!sender) { gs.log(myname + ': No sender address', myname); return; } // Reply To field is used OOB only for Sent emails // So use this field to save the sender's email address current.reply_to = sender; matchUserByAltEmail(); if (!current.user_id) { gs.log(myname + ': No user found for address: ' + current.user, myname); } function matchUserByAltEmail(){ // Match on u_alternate_email var grUser = new GlideRecord('sys_user'); if (sender && grUser.get('u_alternate_email', sender)) { current.user_id = grUser.getUniqueValue(); current.user = grUser.getUniqueValue(); gs.log('Email ' + current.sys_id + ' matched ' + sender + ' to u_alternate_email for ' + grUser.name, myname); } } })(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2020 08:39 AM