How to check whether first name and last name entered on the form already exist or not ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2018 09:55 AM
Hi experts,
I have two fields on the form, first name and last name and I have a back end table in which all user attributes are present including first name and last name.Once the user enters first name and last name I would like check whether combination of first name and last name already present in table or not, if present give an alert message. Find the below image
if a user with same first name and last already exist then have to give a pop-up message in the form.I wrote two scripts, onchange of first name and onchange of last name but it is leading to an infinity loop as both are working one after another. Is there any better idea to fulfill this requirement ??
Regards,
Venkatesh
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2018 10:10 AM
Instead of onChange, You can create onSubmit client script that validates both fields together.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2018 10:50 AM
Although I would not recommend it since this would make the form slower and affect user experience, you can write an onChange client script like so:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var firstName = g_form.getValue('first_name');
var lastName = g_form.getValue('last_name');
var a = new GlideRecord('sys_user'); //replace with your back end table name//
a.addQuery('first_name',firstName);
a.query();
a.addQuery('last_name',lastName);
a.query();
if(a.next()){
alert('user exists');
}
else{
alert('no problemo');
}
}
Apply this client script on change of the last name field. Do not apply any script on the first name field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 02:41 AM
Hi Moy,
Thanks for your response. If I write script only on change of last name, It will work only if user enters first name then last name but it doesn't if user first enters last name then first name. I would like to validate in both the ways. Can I do it with business rule ?
regards,
venkatesh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2018 09:11 AM
Sure, you can do it through a business rule.
var a = new GlideRecord('sys_user'); //replace with your back end table name//
a.addQuery('first_name',current.first_name);
a.query();
a.addQuery('last_name',current.last_name);
a.query();
if(a.next()){ //check if user present already
current.setAbortAction(true);
gs.addErrorMessage('user exists, please try again');
}
else{
gs.addInfoMessage('User added');
}