GlideRecord, not working in server script of a widget

Manimozhi4
Kilo Contributor

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

6 REPLIES 6

Shweta KHAJAPUR
Tera Guru

I think the getRowCount method is not supported in the service portal. Please go through this link to know methods supported by portal,

https://docs.servicenow.com/bundle/london-servicenow-platform/page/build/service-portal/reference/cl...

Manimozhi4
Kilo Contributor

Thanks for your response. It is working now, when I log into the instance directly. However its not working when I impersonate as another user. Also, getRowCount() is working in portal.

Thank & Regards,

Manimozhi