The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How can you get the recent impersonation list for a user?

heather_mcmanig
Kilo Contributor

I'm recreating the impersonate modal in a portal page menu and have it nearly finished. I still need the list of recent impersonations that the user has recently attempted. Is there any way to access this data?

Thanks!

4 REPLIES 4

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

I see you may have duplicated your post to the Community.   See the answers in this thread:


How do you get the recent list of Impersonations attempts for a user?


chirag_bagdai
ServiceNow Employee
ServiceNow Employee

Hi Heather,



I found below API which is being used for impersonate but so far you need to pass username and password for authentication.


I am looking for a way to avoid sending username and password if the user is logged.



var request = new sn_ws.RESTMessageV2();


request.setEndpoint('https://INSTANCE_NAME.service-now.com/api/now/ui/impersonate/recent');


request.setHttpMethod('GET');



//Eg. UserName="admin", Password="admin" for this code sample.


var user = 'admin';


var password = 'admin';




request.setBasicAuth(user,password);


request.setRequestHeader("Accept","application/json");




var response = request.execute();


gs.log(response.getBody());


Chirag, there is a duplicate thread as noted above. The following works too



The list of recent impersonations is stored in a user preference record named recent.impersonations. You can use the following script to get the list for the current logged in user:


gs.getUser().getPreference("recent.impersonations")



This should output a string separated by commas.


If you want to go this route of using the REST API, you can invoke it client side and pass the user session token for authentication. See this thread for examples.


Is it possible to call a scripted REST API from a client script?



Please mark any post helpful or the correct answer to your questions so others can benefit.