Impersonating a user in server script and impersonating back to the original user

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 01:10 AM
Hello, I need help with impersonating a user in server script and impersonating back to the original user. Whats the best way to accomplish this ?
I have tried GlideImpersonate. Here is the code
gs.addInfoMessage(gs.getUserDisplayName());
var y = new GlideImpersonate().impersonate('a8f98bb0eb32010045e1a5115206fe3a');
gs.addInfoMessage(gs.getUserDisplayName());
new GlideImpersonate().impersonate(y);
gs.addInfoMessage(gs.getUserDisplayName());
The output i get when i try to execute in background scripts is
But, when i try to do the same in script include, I get the following output
Here, the script is able to impersonate to Abraham Lincoln, but isn’t able to impersonate back to System Administrator.
Can you please tell me where am i going wrong ?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 01:19 AM
Hi
Maybe
gs.addInfoMessage(gs.getUserDisplayName()); //admin
var y = new GlideImpersonate().impersonate('a8f98bb0eb32010045e1a5115206fe3a');//stored abraham in y
gs.addInfoMessage(gs.getUserDisplayName()); //abraham because impersonated
new GlideImpersonate().impersonate(y); //again impersonating to abraham // here try sys_id of admin
gs.addInfoMessage(gs.getUserDisplayName());//same as expected.(abraham)
Hope it helps.
Mark Correct if it does.
Regards,
Omkar Mone
www.dxsherpa.com

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 01:24 AM
In variable y, the sys_id of the user that was logged in prior to the impersonation request is stored.
Please check https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 01:28 AM
Hi
Is the value passed inside first impersonate that of Abraham or System Admin?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2018 01:29 AM
Hello,
Its of Abraham.