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

Eliz Kotadia
ServiceNow Employee
ServiceNow Employee

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

find_real_file.png

But, when i try to do the same in script include, I get the following output

find_real_file.png

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 ?

5 REPLIES 5

Hi 

So yes it'll impersonate to abraham only....try passing admin sys_id there.