Incoming mail is processed through inactive user instead of active one

jussisaukkonen
Tera Contributor

Hello,

I have a problem with inbound actions. This is the case: multiple users have same email address and one of the users is locked out or inactive. When an email is sent from this email address, the system randomly maps the email address to one of the users in the system. If the user is locked out or inactive, then all the inbound actions are skipped. I would like the system to map the email address to active user rather than inactive one. I know that the user's email address should be unique in ServiceNow but these users are coming from AD and I can't do much about it.

I tried to create before business rule in the 'sys_email' table and change the user but this has no affect to the user through which the inbound actions are run. Only solution I can think of is to change the inactive user to active in the before business rule but this doesn't seem a sustainable solution.

This behavior occurred when we updated the instance to the Berlin release. Therefore I would like to know what options do I have? Is there a property that controls this behavior or can I somehow control the user mapping of the email?

All help is appreciated!

1 ACCEPTED SOLUTION

michael_baker
Tera Guru

The solution we implemented was to create a before business rule on the Email table that runs when the type is "received", the mapped user is inactive, and the mapped user's email is not blank. If this condition is met we query the User table to find if an active user exists with the same email address and then set the email's mapped user to this active user.

Name: Check for Inactive User
Table: Email [sys_email]
When: before
Insert: true
Condition: current.type == 'received' && current.user_id.active == false && current.user_id.email != ''
Script:



var grUser = new GlideRecord ('sys_user');
grUser.addQuery('email', current.user_id.email);
grUser.addActiveQuery();
grUser.orderBy('sys_created_on');
grUser.query();
if (grUser.next()) {
current.user = grUser.sys_id;
current.user_id = grUser.sys_id;
}


Hope this helps!


View solution in original post

12 REPLIES 12

Ryan Gladwyn-Na
Giga Expert

A workaround is to remove the email address of inactive users.


CapaJC
ServiceNow Employee
ServiceNow Employee

I took a look at the code, and unfortunately the backend code that createUser calls into to match an email address to a sys_user record cannot currently be told to prefer the active user to the inactive ones. It implicitly assumes that two users will not have the same email address.

So Ryan's suggested workaround may be your only option with current code: either remove or modify the email address for the inactive duplicates. You could add a "z" or "inactive_" to the start of the address.


pravTel
Kilo Contributor


CapaJC



Thanks CapaJC and Ryan. As suggested, we had to add a similar prefix to the email Ids for existing user records with this issue.
The only problem is that, as we have synchronised Servicenow with LDAP, whenever a user (who would have been terminated in the past) is created again with an existing email id (which occurs quite regularly in our systems) this issue will reoccur.
I will have to modify LDAP transformation script and the User form to check if the Email Id exists already and if so set a prefix for all the existing records with this Email Id.

Regards,
PravTel


michael_baker
Tera Guru

The solution we implemented was to create a before business rule on the Email table that runs when the type is "received", the mapped user is inactive, and the mapped user's email is not blank. If this condition is met we query the User table to find if an active user exists with the same email address and then set the email's mapped user to this active user.

Name: Check for Inactive User
Table: Email [sys_email]
When: before
Insert: true
Condition: current.type == 'received' && current.user_id.active == false && current.user_id.email != ''
Script:



var grUser = new GlideRecord ('sys_user');
grUser.addQuery('email', current.user_id.email);
grUser.addActiveQuery();
grUser.orderBy('sys_created_on');
grUser.query();
if (grUser.next()) {
current.user = grUser.sys_id;
current.user_id = grUser.sys_id;
}


Hope this helps!


Sorry for late reply. The business rule that you provided solved the problem. I actually tried something similar by myself but didn't get it to work.

This is the best workaround for this problem so far.

Thank you.