User Query by Domain

kchorny
Tera Guru

I'm building some sub-domains in our instance, and I've run into an issue with a user query business rule.   The requirement is that a user in the domain can see all other users in their domain as well as users in any domains that are children of their domain.   I've created the below before query business rule on the sys_user table in the sub-domain.   It fulfills the requirement, but when it's turned on, I can't impersonate anyone!   When I'm logged in with my admin account (which is in the global domain) and attempt to impersonate anyone in any domain, it just goes back to my admin account.

Is there a condition I can put in the rule that will keep it from running when changing impersonation?

Here is the current condition:

gs.hasRole("itil") && gs.getSession().isInteractive()

And the script:

var cDomain = gs.getUser().getDomainID();

var q = current.addQuery('sys_domain',cDomain);

var sd = new GlideRecord('domain');

sd.addQuery('parent',cDomain);

sd.query();

while (sd.next())

{

q.addOrCondition('sys_domain',sd.sys_id);

}

Thanks for any help!

1 ACCEPTED SOLUTION

Use this instead.



gs.hasRole("itil") && gs.getSession().isInteractive() && !gs.getImpersonatingUserName()



Reference: Business Rule condition ignore if trying to impersonate



Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

6 REPLIES 6

SanjivMeher
Kilo Patron
Kilo Patron

In the condition, you should try



gs.hasRole("itil") && gs.getSession().isInteractive() && !gs.hasRole("admin")



Please mark this response as correct or helpful if it assisted you with your question.

That works to impersonate the first user, but then I can't go back and have to turn off the rule to get back to my admin acct.   Is there anything else I can do?


Use this instead.



gs.hasRole("itil") && gs.getSession().isInteractive() && !gs.getImpersonatingUserName()



Reference: Business Rule condition ignore if trying to impersonate



Please mark this response as correct or helpful if it assisted you with your question.

That did it, thank you very much!