logo

NJP

Impersonate user in assignment group

Import · Dec 09, 2019 · article

Hello everybody,

during tests, it is often necessary to impersonate users who are in the ticket assignment group.To speed up this operation, I created an UI Action, which allows you to impersonate a (random) user of the assignment group.

image

A message indicates which user was impersonated

image

This is the UI Action

Name: Impersonate user in group

Table: Catalog Task (select the desired table)

Condition:

current.assignment_group && ( gs.getUser().hasRole("impersonator") || gs.getImpersonatingUserName() != "" )

Script:

// Retrieve user in group
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("group",current.assignment_group);
gr.addQuery("user.active",true);
gr.addQuery("user.sys_id","!=",gs.getUserID()); // Me
gr.setLimit(1);
gr.query();

// Impersonate
if(gr.next()){
    session.onlineImpersonate(gr.user);
    gs.addInfoMessage("Impersonated: " + gr.user.name);
    action.setRedirectURL(current);
} else {
    gs.addInfoMessage("No user impersonated! Please check the members of the group");
}

I hope it's useful!

Corrections and comments are welcome image

Daniele

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/impersonate-user-in-assignment-group/ta-p/2302009