Justin Bakker
ServiceNow Employee
ServiceNow Employee

The ability to impersonate users is a great tool in our troubleshooting arsenal. You don't depend on screen shares to see what the end user is seeing and there's no need to log in as the user. Simply impersonate the user and run your tests. This makes it a whole lot easier to run through your test case.

But it's functionality you need to be careful with as you can do a lot of damage impersonating someone. You can already do this by limiting who has this option, it should only be available for people who have a benefit of checking this behaviour like support engineers and system administrators. And you can turn the whole thing off via glide.ui.impersonate_button.enable if you so desire, but what if you want to limit the people that can be impersonated? Can you do this as well? The short answer is yes, there's no out-of-the-box option but with the platform being so customisable, you can just build your own.

You can’t change the query that goes out but you can add a Business Rule which runs on Before Query on sys_user amending the query by updating EncodedQuery. For example, this would limit the available users to People called James, just to illustrate the principle. 

Notice it runs before sys_user on Query.

 

find_real_file.png

 

I added a condition based on a few tests to limit it as much as possible. The script field is where the query is limited. So the idea is to check the URL so we know it's a request to return the users who can be impersonated (line 3). We then intercept and adjust the query in line 4 via addEncodedQuery. You can change this to whatever you need: groups, location, etc. Just work out the encoded query and add it.

 

find_real_file.png

 

 

The end result looks like this:

find_real_file.png

 

 

Best wishes,

Justin

3 Comments