Catalog Client Script for validating User ID and email based on user inputs , in case if it exist pop user to change it as it not availabe. 2.User ID auto populating on the form as first_name.last_name and emai as first_name.last_name@3com.com

sachinam33
Kilo Explorer

Requirement of 1.catalog Client Script which could validate User ID and email based on input ,in case if it already exist pop user to change it as it not available.

2. User ID auto populating on the form as first_name.last_name and emai as first_name.last_name@3com.com both to be editable feilds.

Regards,

Sam

5 REPLIES 5

Chuck Tomasi
Tera Patron

Hi Sachin,



Both of these are completely do-able. For the first one I recommend using a GlideAjax call to a script include that verifies the name/email is available.



For the second, you can simply use an onChange client script that takes the content of the first field and appends the appropriate suffix for you.



Docs: Client Scripts


Docs: GlideForm


Docs: GlideAjax


Client Script Best Practices - ServiceNow Wiki      


Hi Chuck,



I am new to SCripting had used below to check ID but it not working,Can you please let me know the changes needs to be done.



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }


var userID = g_form.userID;


var gr=new GlideRecord('sys_user');


gr.addQuery('userID',userField);


gr.addQuery('user', usrID);


if(gr.next())


alert("Entered User ID already Exists. Please change the value");


g_form.setValue('userID','');



    //Type appropriate comment here, and begin script below



}



find_real_file.png


Try this:



function onChange(control, oldValue, newValue, isLoading, isTemplate) {


    if (isLoading || newValue === '') {


          return;


    }


var userID = g_form.userID;


var gr=new GlideRecord('sys_user');


gr.addQuery('user_name', userID);


if(gr.next())


alert("Entered User ID already Exists. Please change the value");


g_form.setValue('userID','');



    //Type appropriate comment here, and begin script below



}


Hi Chuck



Thanks for the script. but as user id is entered on the form its disappearing.Even if its new userid is entered



Any advice.



Regards,



Sam