sshall
Mega Expert

I recently encountered the same issue in trying to implement custom dimensions for Google Analytics. I wanted to add a dimension based on user roles. There is a way to do it without a GlideAjax call, though I must say this is about as far into the weeds as you can get from a platform perspective.



View the page source within ServiceNow, and about 60 lines down you'll find:



window.NOW.user = {};


window.NOW.user.preferences = [];


window.NOW.user.roles = 'admin';


window.NOW.user.id = '6816f79cc0a8016401c5a33be04be441';


window.NOW.user.departmentID = 'a581ab703710200044e0bfc8bcbe5de8';


window.NOW.user.firstName = 'System';


window.NOW.user.lastName = 'Administrator';


window.NOW.user.name = 'admin';



Within your UI Script, you can reference these variables, in particular the window.NOW.user.roles variable, to get the list of roles for the current user.


Hey Scott,



It looks like cheat code. But it helped me. Thank you for sharing this.



Thanks


Hey Scott,

 

window.NOW.user.roles doesn't work in portal, any guidance?

try this

from snprotips:

find_real_file.png

syed_faheem
ServiceNow Employee

You can use top.window.NOW object which has many different useful attribute as below:

top.window.NOW.instance_name

top.window.NOW.page_id

top.window.NOW.portal_id

top.window.NOW.portal_url_suffix

top.window.NOW.user_display_name

top.window.NOW.user_id

top.window.NOW.user_id_hashed

top.window.NOW.user_impersonating

top.window.NOW.user_initials

top.window.NOW.user_name

 

Cheers

Syed.