- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-14-2024 11:50 PM
I have a single line text field called "email address", need to have a validation check for that field, if there is already email available in the user table which is same as the end user entered, we should throw the error saying that this email address is already exist,please choose different one.
Please help me in script part for this.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2024 05:47 PM - edited ‎03-16-2024 06:19 PM
Hi @Archana23 sorry while copying client script i missed a line where there is a error in your client script your not comparing answer is true which is failing . Corrected below check bolded line which is missing in your code
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-17-2024 02:38 AM
Perfect! It is working as expected now.
Thanks for your indetail explanation @Harish KM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2024 12:21 AM
something like this.
onChange client script:
var ga = new GlideAjax('EmailValidation');
ga.addParam('sysparm_name', 'checkEmail');
ga.addParam('sysparm_email_id', newValue);
ga.getXML(emailValue);
function emailValue(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == 'true') {
alert('This email is already exists. Please enter another email id');
g_form.clearValue('<enter email field backend name>');
}
}
Client callable script include:
checkEmail:function() {
var getTask = new GlideRecord('sys_user');
getTask.addQuery('email', this.getParameter('sysparm_email_id'));
getTask.query();
if (getTask.next()) {
return true;
} else
return false;
},

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2024 09:42 AM
Hi @Archana23 Can you try with this script.
Catalog Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var ga = new GlideAjax('validateEmail');
ga.addParam('sysparm_name', 'email_validation');
ga.addParam('sysparm_email', newValue);
ga.getXML(emailVal);
function emailVal(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
if (answer == 'true') {
alert('Email Already Exist ! ');
g_form.clearValue('email');
}
}
}
Script Include :
var validateEmail = Class.create();
validateEmail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
email_validation: function() {
var mail = this.getParameter('sysparm_email');
var grm = new GlideRecord('sys_user');
grm.addQuery('email', mail);
grm.query();
if (grm.hasNext())
return 'true';
else
return 'false';
},
type: 'validateEmail'
});
Hope it will help you.
Thanks,
Harsh