Error message populating if the user's first name and last name is in AD throw an error in catalog

Ravichandra2
Tera Contributor

In Catalog item Form if we type the same first name and last name which is present in Active Directory it will throw an error on OnChange Function.

 

 

Thanks,

Ravichandra

4 REPLIES 4

Amarjeet Pal
Kilo Sage
Kilo Sage

Hello @Ravichandra2 ,

Could you please add some screenshot or what error it is displaying.

 

Thanks

Amarjeet Pal

I want Show the Error message when the user selects the name which is present in the sys_user table in a catalog item through the client script on change i tried with some script but it didn't work

This is the script i used

 

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

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

   }
   var usr = new GlideRecord('sys_user');
   usr.addQuery('first_name',updated_firstname);
   usr.addQuery('last_name',updated_lastname);
   usr.addQuery('middle_name',middle_intial_a);
   usr.query();
   if(usr.next())
   {
   alert('User Name already exixts');
   g_form.setValue('updated_firstname','');
   g_form.setValue('updated_lastname','');
   g_form.setValue('middle_intial_a','');
   }

}
 
 
Thanks,
Ravichandra

Hi Ravichandra2,

                           You can't use GlideRecord in client script.For that you have to write a GlideAjax and fetch the server side value in the script include.

Please mark it as helful if it helps you.

Thanks & Regards,

Satyapriya

Hello @Ravichandra2 ,

Just a brief explanation of using GlideAjax . Hope you will find this Helpful

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var ga = new GlideAjax('CheckUserName');
   ga.addParam('sysparm_name', 'checkUser');
   ga.addParam('sysparm_firstname', g_form.getValue('updated_firstname'));
   ga.addParam('sysparm_lastname', g_form.getValue('updated_lastname'));
   ga.addParam('sysparm_middleinitial', g_form.getValue('middle_intial_a'));

   ga.getXML(function(response) {
      var answer = response.responseXML.documentElement.getAttribute("answer");
      if (answer == 'true') {
         alert('User Name already exists');
         g_form.setValue('updated_firstname','');
         g_form.setValue('updated_lastname','');
         g_form.setValue('middle_intial_a','');
      }
   });
}
```

This version of the script creates a new instance of GlideAjax and provides it with the name of the server-side script to call (`CheckUserName`) and any necessary parameters (`firstname`, `lastname`, and `middleinitial`). It then calls the `getXML` method on the GlideAjax object to asynchronously execute the server-side script and receive its response.

The server-side script (`CheckUserName`) would need to be created separately in order for this code to work. The `checkUser` function within that script would accept the parameters provided by the client-side script, perform a query on the `sys_user` table using those parameters, and return a true or false value indicating whether a matching record was found.

Thanks

Amarjeet Pal