How to query the user table in client script?

dasbiswa
Tera Expert

How to query the user table in client script?

3 REPLIES 3

Brandon Smith3
Kilo Expert

If you are trying to look for a record or value on the user table you can use a Glide Record.



var gr = new GlideRecord('sys_user');


gr.addQuery('name_of_field', value)


gr.query()


more information on GlideRecord can be found below :


http://wiki.servicenow.com/?title=GlideRecord#gsc.tab=0


Rohit Sarkar1
Mega Guru

Hi Biswajyoti do you need to check multiple records?
       



if suppose there is a field(xyz) which refers to the "user" table then you can do this:



var abc = g_form.getValue('xyz');


var gr= new GlideRecord('sys_user');


gr.addQuery('sys_id',abc);


gr.query();


if(gr.next()) OR while(gr.next())


{


then perform action


}


Kostya
Tera Guru

Everything above is true. But, the best practice is NOT to use GlideRecord in a client script. Please avoid it and use GlideAjax instead! Please refer to GlideAjax for further details!



Depends on your needs you can use a g_scratchpad as well: Scripting with display business rules


Hit the Thumb Icon and/or mark as Correct, if my answer was correct. So you help others to see correct responses and I get fame 🙂

Cheers,
Kostya