GlideRecord, not working in server script of a widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 09:56 PM
Hi,
I'm trying to glide the user table and query with the currently logged in user's sys_id in the server script of a widget, for a requirement. But, the GlideRecord seems not working in the server script. getRowCount() function is returning 0 record. Please find the code below.
data.pop_up_message = gs.getMessage('Must see info');
data.logged_in = 'true';
data.userId = gs.getUserID();
var usr = new GlideRecord("sys_user");
usr.addQuery("sys_id", data.userId);
usr.query();
gs.log("user count is " +usr.getRowCount());
if(usr.next())
{
gs.log("user name is " +usr.name);
data.logged_in = usr.u_service_catalog_info.toString();
}
else
{
gs.log("user query is wrong");
}
Please help me with your suggestions.
Thanks in advance,
Manimozhi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 10:06 PM
try below code:
var userId = gs.getUserID();
var usr = new GlideRecord("sys_user");
usr.addQuery("sys_id", userId);
usr.query();
gs.log("user count is " +usr.getRowCount());
if(usr.next())
{
gs.log("user name is " +usr.name);
data.logged_in = usr.u_service_catalog_info.toString();
}
else
{
gs.log("user query is wrong");
}
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 11:00 PM
Tried this too. But, it is not working.
Thanks & Regards,
Manimozhi

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 11:03 PM
add log statement and let me know what you are getting in log.
gs.log("query is: "+usr.getEncodedQuery());
Thank you,
Ali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2019 11:11 PM
Try below code,
data.userId = gs.getUserID();
gs.addInfoMessage("user sys_id"+data.userId);
var usr = new GlideRecord("sys_user");
if(usr.get(data.userId)){
gs.addInfoMessage("user name is " +usr.name);
data.logged_in = usr.u_service_catalog_info.toString();
}else{
gs.addInfoMessage("user query is wrong");
}