- 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-15-2024 06:06 PM - edited 03-16-2024 06:18 PM
Hi @Archana23 I tested in PDI, it works fine for me
Script Include:
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 09:10 AM
Hi Harish,
I tried the above script it is working for the existing email, it is showing the error and clearing the value.
But If I give the email which is not available in the user table, the alert is triggering to false from the browser but in this case also it is clearing the entered value and showing the field message 'EMAIL ALREADY EXIST'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 10:02 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2024 10:10 AM - edited 03-16-2024 10:10 AM
@Archana23 Have you tried with the script which i sent you ?
I can see you don't have if block in your client side scripting.
Script include
var SE_Validationcheckforemail = Class.create();
SE_Validationcheckforemail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validateEmail:function(){
var mail = this.getParameter('sysparm_email'); // get email value from client script
var email = new GlideRecord('sys_user');
email.addQuery('email',mail);
email.query();
if(email.hasNext())
return 'true';
else
return 'false';
},
type: 'SE_Validationcheckforemail',
});
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var email = g_form.getValue('email_of_the_shared_mailbox');
var ga = new GlideAjax('SE_Validationcheckforemail');
ga.addParam('sysparm_name', 'validateEmail');
ga.addParam('sysparm_email', email);
ga.getXMLAnswer(response);
function response(answer) {
if (answer == 'true') {
g_form.setValue('email_of_the_shared_mailbox', '');
g_form.showFieldMsg('email_of_the_shared_mailbox', "EMAIL ALREADY EXIST",'error');
}
}
}

- 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