- 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 06:17 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 06:18 AM
Yes, I need to use it in a ACL script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 06:24 AM
Hi Chuck,
gs.getUserId() should work.
He goes an example impersonating through script and proving that it works:
gs.print('This is my UserID:' + gs.getUserID());
var imp = new GlideImpersonate();
// Enter below the ID of the user you will like to impersonate
var previousUserId = imp.impersonate('014457ec4f678a0026afb1828110c7fa');
gs.print('This is the other person UserID:' + gs.getUserID());
if (previousUserId) imp.impersonate(previousUserId);
gs.print('This is my UserID:' + gs.getUserID());
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-02-2015 06:26 AM
You can run this script from a background script using elevated privileges.
The output will be something like the following:
*** Script: This is my UserID:xxxx083c4fc0920026afb1828110xxxx
*** Script: This is the other person UserID:014457ec4f678a0026afb1828110c7fa
*** Script: This is my UserID:xxxx083c4fc0920026afb1828110xxxx
Thanks,
Berny