
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2023 09:42 AM
Hello Community,
Following is a business rule to check for duplicate values in the sys_user table during insert. If duplicate is found, abort action. The script is working.
I am looking for assistance scripting the gs.addInfoMessage to show what field was found to be a duplicate (User ID or Email), e.g. User with this <user_name> already exists, User with this <email> already exists.
(function executeRule(current, previous /*null when async*/ ) {
var grUsr = new GlideRecord('sys_user');
grUsr.addQuery('user_name', current.user_name).addOrCondition('email', current.email);
grUsr.query();
if (grUsr.hasNext()) {
current.setAbortAction(true);
gs.addInfoMessage("User with this information already exists");
}
})(current, previous);
Thank you.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2023 10:08 AM
try below (you can add value anywhere I added it to the end)
(function executeRule(current, previous /*null when async*/ ) {
var grUsr = new GlideRecord('sys_user');
grUsr.addQuery('user_name', current.user_name).addOrCondition('email', current.email);
grUsr.query();
if (grUsr.next()) {
current.setAbortAction(true);
if (grUsr.user_name == current.user_name) {
gs.addInfoMessage("User with this user id already exists " + current.user_name);
} else if (grUsr.email == current.email) {
gs.addInfoMessage("User with this email already exists " + current.email);
} else {
gs.addInfoMessage("User with this information already exists");
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2023 10:08 AM
try below (you can add value anywhere I added it to the end)
(function executeRule(current, previous /*null when async*/ ) {
var grUsr = new GlideRecord('sys_user');
grUsr.addQuery('user_name', current.user_name).addOrCondition('email', current.email);
grUsr.query();
if (grUsr.next()) {
current.setAbortAction(true);
if (grUsr.user_name == current.user_name) {
gs.addInfoMessage("User with this user id already exists " + current.user_name);
} else if (grUsr.email == current.email) {
gs.addInfoMessage("User with this email already exists " + current.email);
} else {
gs.addInfoMessage("User with this information already exists");
}
}
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2023 01:40 PM
Thank you!