Querying Another table from Client Script

nehapateria
Kilo Expert

Hi Members,

I have a simple query. I am trying to query 'sys_user' table from my Custom form. I am querying 'user_id'   of my current form to 'user_name' of 'sys_user' table. If the record is found then a user must get an alert that the same UserId exists in the system. For that I have written the below Client Script. Issue is :- I am getting a below error message in the 'user_id' field.

Error:-

onChange script error: TypeError: GlideRecord is not a constructor function (){var o=i(m,arguments);return l.apply(n,o)}

Please Suggest.

Thanks,

Neha

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

                              if(isLoading)

                              {

                                                              return;

                              }

                              var gr1 = new GlideRecord('sys_user');

                              gr1.addQuery('user_name', newValue);

                              gr1.query();

                              myFunc();

                             

                              function myFunc()

                              {

                                while(gr1.next())

                                    alert('USER ID already exists');

                              }

    //Type appropriate comment here, and begin script below

   

}

1 ACCEPTED SOLUTION

Hi Neha ,



Try something as below in script include:-



var sysid = this.getParameter('sysparm_sys_id')   ;
var gr1 = new GlideRecord('sys_user');


                              gr1.addQuery('sys_id', sysid )


                              gr1.query();
                         


                                while(gr1.next())


                                    gs.log('user exists');


                                      return true;
                              }




Mark Correct if it solved your issue or hit Like and Helpful if you find my response worthy.


Thanks,
Deepa


View solution in original post

39 REPLIES 39

What is the value in NewValue   and which field it is?


this is not rite, it is not given value, so your parameters are not going to script include.



  var sysid = g_form.getValue('sys_id'); //wrong



write:


var sysid = g_form.getValue('caller');



so your caller sysid will go to script include.



and make your scripts on change of nything



var sysid = g_form.getValue('caller_id'); my bad


Hi Deepa/Ashutosh,



Let me please re-iterate. I have created one custom form that has string field called 'userid'. While entering the value in this field it should check whether the same user id is existing in the 'sys_user' table (i.e. User form). The field which I am referring in User form is 'user_name'. If the same user id is found in User form then User must be alerted that "USER ID already existing".  



I wrote the client script 'OnChange' in the 'userid' field of the custom form.


ok so new value is prompting user_name right?


Also please post the code of Script include which you have written..