- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 06:00 AM
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!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 07:30 AM
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");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 10:07 AM
I know what you're saying and that is an option I've considered, but sometimes we need to impersonate to see how the form reacts from the user perspective (not ours) so this would allow us to still impersonate and use our data, but get to see and test how the form reacts for that user.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 10:27 AM
Right.
Unfortunately though, impersonation is not a true test because sometimes your admin privileges "leak" through and give you more access than you should have. I always create 3 accounts for myself - admin, role and ess. I will actually log in with my role or ess account (depending on what I'm testing) to do the real test to be 100% sure. I'm been burned in the past with impersonations. I still use it for quick checks, but not for any real testing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 10:36 AM
Jim, that's great advice. I've also seen leak issues, especially when logged in on one screen and impersonating on another. But since impersonating is allowed, we still need a way to limit the access to our own HR data regardless if we are impersonating or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 09:00 AM
Hi Chuck,
You can try this too;
var impersonatingUser = gs.getUser();
impersonatingUser = impersonatingUser. getUserByID( gs.getImpersonatingUserName()).sys_id;
Regards
Hardik Vora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 09:55 AM
Hardik, I think you might be on to something here, but I can't get that code to run clean. That first statement would put the user name (of person i'm impersonating), in impersonatingUser variable, then overwriting that variable with second statement that's not making sense to me since it has the person that I'm impersonating at the beginning and also fetching user id of impersonator (me). Not making sense tome and it is getting a script error. Can you look another look at that stmt or try to run it your self? Thanks.