- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2018 06:42 AM
Hi Guys,
I created a catalog item with 3 fields, First name, last name and User id.
Based on the inputs given in First name & last name the User id field gets auto populated with the two inputs.
my requirement is... if the User id field value already exists in sys_user table ( if the User id field value matches user_name in sys_user table). Then on Submit of the form an alert or error message must be thrown like, User id already exists- please try different name. By glide recording sys_user table i have to do this. But can you say me how to do this?
Regards,
VIjay
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2018 06:59 AM
Hi vijay,
Create an onSubmit catalog client script and put the code below:
function onSubmit() {
var usr = new GlideRecord('sys_user');
usr.addQuery('user_name',g_form.getValue('user_name'));
usr.query();
if(usr.next())
{
alert('User ID already exixts');
g_form.setValue('user_name','');
return false;
}
}
Hope this will fit your need.
Please, remember to mark Correct or Helpful if you find my response useful.
Cheers
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2018 06:59 AM
Hi vijay,
Create an onSubmit catalog client script and put the code below:
function onSubmit() {
var usr = new GlideRecord('sys_user');
usr.addQuery('user_name',g_form.getValue('user_name'));
usr.query();
if(usr.next())
{
alert('User ID already exixts');
g_form.setValue('user_name','');
return false;
}
}
Hope this will fit your need.
Please, remember to mark Correct or Helpful if you find my response useful.
Cheers
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2018 11:49 PM
Hi,
Any update on this?
Can you mark my answer as correct, helpful and hit like if you were able to achieve the requirement. This helps in removing this question from unanswered list and helps users to learn from your thread.
Thanks in advance.
Cheers
Alberto

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2018 07:03 AM
I would suggest you to include this validation in the same script where User ID field gets populated( I believe that's On Change). Validation on OnSubmit in not a best practise but if would like check this https://snprotips.com/blog/2018/10/19/synchronous-lite-onsubmit-catalogclient-scripts.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2018 07:04 AM
Greetings vijay,
You can do this with a onChange client script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var usr = new GlideRecord('sys_user');
usr.addQuery('user_name',newValue);
usr.query();
if(usr.next())
{
alert('User Name already exixts');
g_form.setValue('name','');
}
}
Or with an onsubmit
function onSubmit() {
var usr = new GlideRecord('sys_user');
usr.addQuery('user_name',g_form.getValue('user'));
usr.query();
if(usr.next())
{
alert('User Name already exixts');
g_form.setValue('user','');
return false;
}
}