Business Rule condition ignore if trying to impersonate

nathan34
Giga Contributor

I have an onBefore business rule that limits user query results based on which domain a user exists in.   This rule interferes with trying to impersonate back to myself from a non-admin user (causes me to have to logout and log back in as myself).

Is there a condition I can write that will ignore this business rule if trying to impersonate?

1 ACCEPTED SOLUTION

nathan34
Giga Contributor

The working solution I used was posted on here but must have been removed.



I added !gs.getImpersonatingUserName() to the condition line in my Business Rule script and am now able to successfully impersonate back to myself from a non-admin user.



Thanks all!



P.S. That gs.getSession().isImpersonating() looks like it will come in handy down the line too so thanks for that as well.


View solution in original post

13 REPLIES 13

Chuck Tomasi
Tera Patron

Hi Nathan,



Yes, there is an isImpersonating() method available in gs.getSession().



var isImpersonator = gs.getSession().isImpersonating();
gs.info(isImpersonator);



https://developer.servicenow.com/app.do#!/api_doc?v=jakarta&id=r_SGSSN-isImpersonating


Hi Tomasi,

I wonder if there is a way to get the sys_id of the user before the impersonate, brcause the sys_id i got using the gs.getUserID() is the sys_id of the user after the impersonate user.

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Nathan,



Are you saying that you want this business rule not to run when somebody impersonates the user.



Regards


Ankur


Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Bawiskar,

I wonder if there is a way to get the sys_id of the user before the impersonate, brcause the sys_id i got using the gs.getUserID() is the sys_id of the user after the impersonate user.