need to have a validation check for that field, if there is already email available in the user tabl

Archana23
Tera Contributor

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.

1 ACCEPTED SOLUTION

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

 

function response(answer) {
        alert(answer);
       if(answer == 'true')
 {  g_form.setValue('email_of_the_shared_mailbox', '');
            g_form.showFieldMsg('email_of_the_shared_mailbox', "EMAIL ALREADY EXIST",'error');
    }
 
}
}
Regards
Harish

View solution in original post

17 REPLIES 17

Onkar Pandav
Tera Guru

Hi Archana,

In this case you will need a onChange client script and script include.

Script include will check and returns true/false based on the email address availability.

Then client script will throws error/alert based on true/false value from script include.

Hope this helps.

Can you please help me in writing the script.

Harish KM
Kilo Patron
Kilo Patron

Hi @Archana23 you can create a script include like below

script:

validateEmail:function(){
var mail = this.getParameter('sysparm_email'); // get email value from client script
gs.info("email"+mail);
var email = new GlideRecord('sys_user');
email.addQuery('email',mail);
email.query();
if(email.hasNext())
{
    return "Email Already Exist";
}

},

HarishKM_0-1710486352752.png

 

and create a onchange catalog client script on email variable like below

script:

 var email = g_form.getValue('email');
    alert(email);
    var ga = new GlideAjax('demoUtils'); // script include name
    ga.addParam('sysparm_name', 'validateEmail'); // script include function name
    ga.addParam('sysparm_email', email); // pass value to script include
    ga.getXMLAnswer(response);

    function response(answer) {
        alert(answer);
        if (answer) {
            g_form.setValue('email', '');
            g_form.showFieldMsg('email', answer);

        }
    }

 

Regards
Harish

Hi @Archana23 I have already shared the working code 🙂

Regards
Harish