How do I end Impersonation in a script in the workflow

Stacy1
Mega Guru

I am creating new accounts via workflow.  Only Admin can create accounts per business rules to create the account code and path.

So in my workflow I am impersonating admin before creating the account.  

However I need to end the impersonation in the script because it logs the user off.

//Only admin can create accounts, must impersonate admin
var impUser = new GlideImpersonate();
impUser.impersonate('6816f79cc0a8016401c5a33be04be441');
//Create Account

How do I stop impersonating?

Thanks,

Stacy

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

If I am following you correctly then you have impersonated an admin user in the workflow script and now you want to impersonate back to logged in user? I believe you need to re impersonate the logged in user. Try something like this 

var currentUser = gs.getUserID();
var impUser = new GlideImpersonate();
impUser.impersonate('6816f79cc0a8016401c5a33be04be441');
impUser.impersonate(currentUser);

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

View solution in original post

8 REPLIES 8

Stacy1
Mega Guru

So oddly I can have this same approver (without the admin role) create an account in the account table without the error.  So I don't know why I have the problem in the workflow if they don't have the admin role.

I opened a ticket with HI and will let y'all know what they say.

 

thanks,

Stacy

Hi,

 

This is an old thread but I am facing similar situation. Did you get any answer from Hi?

Thanks,

DP

MrMuhammad
Giga Sage

If I am following you correctly then you have impersonated an admin user in the workflow script and now you want to impersonate back to logged in user? I believe you need to re impersonate the logged in user. Try something like this 

var currentUser = gs.getUserID();
var impUser = new GlideImpersonate();
impUser.impersonate('6816f79cc0a8016401c5a33be04be441');
impUser.impersonate(currentUser);

 

Thanks & Regards,

Sharjeel

Regards,
Muhammad

That's what I replied earlier. From the description of the method, it doesn't seem like the method is putting userSysId into a stack as it's done from the GUI.

That is, the method is just switching users and there's no "end impersonation" when calling from a method.