Get data from sys_user table

dmkiraly
Kilo Contributor

Hi

Based on the user's ID, I'd like to get specific data from the sys_user table. Could you help me to achieve that? I'm a newbie and I'm stuck.

I've successfully got the user id from the user reference table:

 

var userIM = g_form.getValue('reqFo');
	console.log(userIM);

'reqFo' is the User [sys_user] reference variable.

Now, by knowing the user ID, how can I get e.g. the user's department (which is stored in the sys_user table as well)?

Like 'select u_department from sys_user where userIM = 123'

Thank you

P.s. I can only use client side code

2 REPLIES 2

Dubz
Mega Sage

Hi,

 

You need to make a call to the server to retrieve that information, you can use getReference() but it's not considered best practice as it opens a client side glide record which basically transfers data on the whole record to the client which is somewhat inefficient if all you need is a single value.

 

You should use a glide ajax instead, this involves adding some script in your client script to call a script include on the server side. The link below gives a good guide, you should also check out episode 33 of TechNow.

 

How to write smart Glide Ajax

 

technow episode 33

cfran5991
Kilo Expert

There are different ways to do this (client side glide record, or getReference), but best practice would probably be to create a script include, and use glideAjax to call it.

 

GlideAjax: https://docs.servicenow.com/bundle/istanbul-application-development/page/app-store/dev_portal/API_reference/GlideAjax/concept/c_GlideAjaxAPI.html

 

Script Includes: https://docs.servicenow.com/bundle/geneva-servicenow-platform/page/script/server_scripting/concept/c_UseScriptIncludes.html

 

In your script include, you can retrieve the user data however, but you might take a look at this: https://www.servicenowguru.com/scripting/user-object-cheat-sheet/

 

I'd advise using getXML, especially if this is going to be used anywhere on the service portal since getXMLWait is not supported there