Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. 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);
5 REPLIES 5

@Tanushree Maiti Thanks. And, Yes I agree and using the Create User step for all the scenarios. But my ask is different as ATF still has lot of limitations when it comes to testing, modularizing the code, reusability, etc., and using different ways to solve is by creating custom step configs, reusable tests, etc.

Create User has Impersonation option which is recommended by ServiceNow, and just trying to use the same but in different need as I have user created already using the Create a User step.