
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 09:13 AM
We have a catalog item that is used to create user records. There is currently no validation to prevent the user from continuing the process if the user already exists. So I'm trying to validate that the email address being entered isn't a duplicate.
This script is not working... please tell me what I need to do to make it work. I would also like to abort the submission with an alert and direct the user back to the Catalog Item or Service Catalog, rather than just showing an error message.
I also tried, in place of lines 4 and 5:
var eAdd = newValue.trim();
which didn't work either.
Thanks for any help!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 10:42 AM
Hi Karla,
If you want to achieve it by onchange client script then you can use below mentioned script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usr = new GlideRecord('sys_user');
usr.addQuery('email',newValue);
usr.query();
if(usr.next())
{
alert('Email Address already exixts');
g_form.setValue('email','');
}
}
and If you want to achieve it by onsubmit you can use below code.
function onSubmit() {
var usr = new GlideRecord('sys_user');
usr.addQuery('email',g_form.getValue('email'));
usr.query();
if(usr.next())
{
alert('Email Address already exixts');
g_form.setValue('email','');
return false;
}
}
Both will work.
Hope this helps.
Regards
Ujjawal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 09:18 AM
Hello Karla,
To abort the submission you need to adjust script as
if()
{
g_form.showFieldMsg();
return false; //Include this additional line
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 10:18 AM
Hi Karla,
From the screenshot you are sharing, You are using ann onChange client script. Either you need to use onSubmit client script and use return false email already exists. OR if you want to continue with onChange client script then you need to blank out the value for email field.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 10:42 AM
Hi Karla,
If you want to achieve it by onchange client script then you can use below mentioned script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usr = new GlideRecord('sys_user');
usr.addQuery('email',newValue);
usr.query();
if(usr.next())
{
alert('Email Address already exixts');
g_form.setValue('email','');
}
}
and If you want to achieve it by onsubmit you can use below code.
function onSubmit() {
var usr = new GlideRecord('sys_user');
usr.addQuery('email',g_form.getValue('email'));
usr.query();
if(usr.next())
{
alert('Email Address already exixts');
g_form.setValue('email','');
return false;
}
}
Both will work.
Hope this helps.
Regards
Ujjawal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2017 12:31 PM
The onChange script you posted is almost exactly what I had to begin with. It wasn't working for me because I had applied it to a request item, and after some digging I realized that it needed to be applied to a variable set instead. Once I changed that, it started working except that I would like to kick the user completely out of the order guide and back to the service catalog when the script finds a duplicate, rather than clear the email field. Is that possible?
I don't want to use onSubmit because there are multiple steps that come after this one in the order guide, and I want to just stop the whole process at the beginning if there's a duplicate.