Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

End impersonation for users with low roles

Evren Yamin
Tera Contributor

Hello,

 

I was building a script on the existing script include "ImpersonateEvaluator" and I was able to to check that if a user that I'm trying to impersonate has a change_manager role, then the current user should have both itil and change_manager role. If the current user only has the itil then the current user will not be able to impersonate a user with a change_manager role.

 

My issue now is the end impersonation. Since I was able to impersonate the change_manager user, I was unable to end the impersonation since the current user that I am currently logged in have both change_manager and itil role.

 

Is there a way to check that if I am impersonating a user with only one role and not both then I can be able to go back to my account? I know this is OOB but I think since I have made changes on the script include it's no longer working.

 

Appreciate all the help

1 ACCEPTED SOLUTION

It would be something like this.

 

if(!gs.hasRole("change_manager"))

   current.addEncodedQuery("roles!=change_manager");

View solution in original post

5 REPLIES 5

It would be something like this.

 

if(!gs.hasRole("change_manager"))

   current.addEncodedQuery("roles!=change_manager");