We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Impersonation from server-side script

Shan C
Giga Guru

I am trying to create a custom server-side step config to add groups/roles to an existing user created part of previous steps or reusable tests, and it seems the executing user should have admin or test designer permissions to do groups/roles to users.

So, I did like below, and it is not working or group/roles getting added. Is there any additional points to consider here or missing anything? Appreciate any inputs.

//Get current user
var current_user = gs.getUserID();

//Impersonate user with permissions to alter user record
gs.getSession().impersonate(inputs.admin_or_test_designer_user);

//My Groups addition code

//Impersonate back to original condition
gs.getSession().impersonate(current_user);
2 REPLIES 2

Ankur Bawiskar
Tera Patron

@Shan C 

is this for ATF?

if yes then why to do impersonation in script?

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

@Ankur Bawiskar Like I mentioned, the current user should have required permissions to add groups/roles to the user. So, trying to impersonate as an admin user, add the group/roles, and continue to the next step. Hope it helps to understand.