How do I get the sys_id of the impersonating user name?

chucksimonds
Kilo Expert

I want/need to get the sys_id of the person impersonating, like getUserID(), but the ID of the person doing the impersonating.

Was hoping there was something like:   getImpersonatingUserID(); but doesn't exist.

I tried this...     var u = gs.getImpersonatingUserName().gs.getUserID();

but it did not work. Any help is appreciated, thanks!

1 ACCEPTED SOLUTION

Hi Chuck,



got it.



You can basically do a simple get with the UserID of the impersonating user - that query is pretty lightweight and shouldn't affect performance too much.


Then you can simply add the sys_id of that person to your query.



You might want to verify if the impersonatingUserSysID is set/filled - if not don't even include it in the answer line (so having two answer lines - one for the case that you have the id and for the case that you don't).



var impersonatingUserName = gs.getImpersonatingUserName();


var impersonatingUserSysID = "";



var grUser = new GlideRecord("sys_user");


if(grUser.get("user_name", impersonatingUserName)) {


        impersonatingUserSysID = grUser.getValue("sys_id");


}


View solution in original post

24 REPLIES 24

And the other thing we did was to exclude the HR table from System Clones (System Clone - ServiceNow Wiki ) so the data would only reside in Production and could not accidentally be accessed in sub-production instances during testing.   The only data that could be in that table was test data.



I just noticed in the Wiki that it states, starting with Dublin, excluded tables that are extended from Task will NOT be excluded, but I do not think that is correct.   They are on Eureka, and only test data exists in the dev instance.   I've requested confirmation on that from the documentation team.


Ashish Kumar Ag
Kilo Guru

getImpersonatingUserDisplayName()   will give you the user name.


Then you can query user table to get the user object.


Don't really want to use a query in an ACL if I don't have to. Was looking for a 1 or 2 line script if possible. Thanks.


srinivasthelu
Tera Guru

Hi Chuck,



In addition to Ashish suggestion, you also have gs.getImpersonatingUserName() function which will get you the user_id.



Thanks


Srinivas


Srinivas, that gets the user id, but not the actual sys_id of the impersonator. That is what I need. Thanks!