- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 07:29 AM
Hello,
We use the gs.createuser method within our Create Incident Inbound Email Action to create INC's for our service desk from external clients. This function is creating duplicate records on the sys_user table with the email being slightly different, the name being null or filled, etc. I also came across this documentation that says that the gs.createUser() method will no longer be supported: https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/notification/referenc...
am wondering what the best alternative to the gs.createUser Method is. The documentation mentions the getUserID method but that works with the currently logged in user which would not be applicable as we are only working with emails sent to our service desk from external clients.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 10:35 AM
Hi
Since you're already using the email property "Automatically create users for incoming emails from trusted domains", in order to avoid duplicate users, you can create a duplicate check business rule on the before insert of "sys_user" table, and check for an existing user using your unique user identifier (in your case if that's the email address), and abort the transaction if a user record is found. That way, your inbound logic would create users, and the before insert business rule shall prevent the creation of a duplicate user.
Steps:
Create a new business rule - Table : User (sys_user)
When to Run: select - Before, Insert;
Select "Advanced"
Under the "Advanced" tab, on Script section, use the below snippet:
(function executeRule(current, previous /*null when async*/) {
var user = new GlideRecord(current.getTableName());
if(current.email) {
user.addQuery('email', current.email.toString());
user.addActiveQuery();
user.query();
if (user.next() && user.sys_id != current.sys_id) {
gs.addInfoMessage("A user record with the same email address already exists in the system. Please deactivate/delete it first to create a new record.");
gs.info("Duplicate user email: "+current.email.toString()+" Aborting action...");
current.setAbortAction(true);
}
}
})(current, previous);
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 08:19 AM
Hi
You can configure the email properties to create new user from the inbound emails, without writing any code.
From the application navigator, navigate to System Properties --> Email Properties, and in the "Inbound Email Configuration" section, check the checkbox "Automatically create users for incoming emails from trusted domains".
Now, on the same configuration page, on the textbox, "Trusted domains....", put in the comma separated values for the domains, from where the inbound emails are usually received, and the incidents are created, and you want a user record to be created if doesn't already exist. You can leave it blank, but that's not advisable, as you don;t want to create a user for every incoming email, and should only be creating it from the domains that you expect the incidents to be coming from. You can always add more domains if needed.
Here are a few other links on similar topic, that you can refer to:
https://hi.service-now.com/kb_view.do?sysparm_article=KB0727801
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 09:52 AM
Hey Rishabh,
We are already using the trusted domains feature. What I'm really trying to do is find a way to sort these emails from multiple domains into user accounts without creating duplicate user accounts.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-06-2020 10:35 AM
Hi
Since you're already using the email property "Automatically create users for incoming emails from trusted domains", in order to avoid duplicate users, you can create a duplicate check business rule on the before insert of "sys_user" table, and check for an existing user using your unique user identifier (in your case if that's the email address), and abort the transaction if a user record is found. That way, your inbound logic would create users, and the before insert business rule shall prevent the creation of a duplicate user.
Steps:
Create a new business rule - Table : User (sys_user)
When to Run: select - Before, Insert;
Select "Advanced"
Under the "Advanced" tab, on Script section, use the below snippet:
(function executeRule(current, previous /*null when async*/) {
var user = new GlideRecord(current.getTableName());
if(current.email) {
user.addQuery('email', current.email.toString());
user.addActiveQuery();
user.query();
if (user.next() && user.sys_id != current.sys_id) {
gs.addInfoMessage("A user record with the same email address already exists in the system. Please deactivate/delete it first to create a new record.");
gs.info("Duplicate user email: "+current.email.toString()+" Aborting action...");
current.setAbortAction(true);
}
}
})(current, previous);
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2020 11:24 PM
Hi
Hope you're doing well. Has this issue been resolved for you?
Please mark the answer as helpful/correct if it has helped you solving your problem, and to close this thread, so that the other community members can refer to it as a resolved thread.
Thanks & Regards,
Rishabh Jha
Aavenir (https://www.aavenir.com/)