Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Give an alert message when user id already exists

vijay39
Giga Expert

Hi Guys,

I created a catalog item with 3 fields, First name, last name and User id. 

Based on the inputs given in First name & last name the User id field gets auto populated with the two inputs.

my requirement is... if the User id field value already exists in sys_user table ( if the User id field value matches user_name in sys_user table). Then on Submit of the form an alert or error message must be thrown like, User id already exists- please try different name. By glide recording sys_user table i have to do this. But can you say me how to do this?

 

 

Regards,

VIjay

1 ACCEPTED SOLUTION

Alberto Consonn
ServiceNow Employee
ServiceNow Employee

Hi vijay,

Create an onSubmit catalog client script and put the code below:

function onSubmit() {

   var usr = new GlideRecord('sys_user');
   usr.addQuery('user_name',g_form.getValue('user_name'));
   usr.query();
   if(usr.next())
   {
   alert('User ID already exixts');
   g_form.setValue('user_name','');
   return false;
   }
}

Hope this will fit your need.

Please, remember to mark Correct or Helpful if you find my response useful.

Cheers
Alberto

View solution in original post

5 REPLIES 5

Vinay Tulaband1
Kilo Expert

create a client callable script include and validate it from onSubmit Catalog Client Script

 

Catalog Client Script : 

Type : onSubmit()

 

function onSubmit(){

var userId = g_form.getValue('user_id');

var ga = new GlideAjax('CheckUserId');

ga.addParam('sysparm_name','checkID');
ga.addParam('sysparm_user', userId);
 ga.getXMLWait();

var res = ga.getAnswer();

if(!res)
{
alert('user id exists');
return false;
}
}


Script Include :


write script to return true if user id exists else return false.