The Now Platform® Washington DC release is live. Watch now!

Help
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

In ATF can you specify a member of a certain group to impersonate?

dp11
Mega Guru

Hi,

In order to test a Change workflow I would like to have a step to impersonate a member of a certain group that can approve the change request. With the OOTB test step Impersonate you can only select a specific individual user. I would like to make it generic so that any member of a group can be selected. Has anyone tried this? 

Thanks,

Deb

 

1 ACCEPTED SOLUTION

If you're in New York or later, you might be better off using the "Create a User" step. You can create a temporary user, assign the temp user to the right group and roles, and then impersonate them all in one step. The advantages of this are that it eliminates the dependency on existing information and rolls back (removes the user) when the test is done.

View solution in original post

5 REPLIES 5

Tim Deniston
Kilo Sage
Kilo Sage

In order to do this, you would need to first get the group value, query the group membership table, then get one of the users from the results. This would be done inside a "Run Server Side Script" test step. Here is the code you would need in that test step to pull the Assignment Group, but it wouldn't be much different to use another sys_user_group reference field instead. If you need to use a separate group entirely, you would need to add another GlideRecord query.

 

(function(outputs, steps, stepResult, assertEqual) {
	var inc = new GlideRecord('incident');
	inc.get(steps('da50d708db3013003751771c8c961977').record_id); //substitute the sys_id from the previous test step that references your change request

	var group = inc.assignment_group;

	var grMember = new GlideRecord('sys_user_grmember');
	grMember.addQuery('group', group);
	grMember.query();

	if (grMember.next()) { //this will get the first group member record that is returned
		outputs.table = 'sys_user';
		outputs.record_id = grMember.user;

		if (outputs.record_id) {
			stepResult.setOutputMessage("Successfully collected user sys_id");
			return true;
		} else {
			stepResult.setOutputMessage("Failed to collect user sys_id"); //This likely means that the group member record is bad
			return false;
		}
	} else {
		stepResult.setOutputMessage("Failed to find group members"); //This likely means that there are no group members
		return false;
	}



})(outputs, steps, stepResult, assertEqual);

 

You can reference the output of this script in future test steps, such as the Impersonate test step.

dp11
Mega Guru

Thank you so much for the above code and explanation. Let me give it a try.

Deb

Jayesh1
Giga Contributor

Hi, 

Can you please give me "Run Server Side Script" for Change request.

Sorry Jayesh, I moved on to other tests and haven't got back to this. As per Tim's suggestion, you will need to create a step using the Run Server Side Script that will return any member of a specified group: 

(function(outputs, steps, stepResult, assertEqual) {
// add test script here

var group = '923ca6a90a0a3caa01521a1d1104d2a5'; // sys_id of a specific group that will approve your Change Request

var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', group);
grMember.query();

if (grMember.next()) { //this will get the first group member record that is returned
outputs.table = 'sys_user';
outputs.record_id = grMember.user;

if (outputs.record_id) {
stepResult.setOutputMessage("Successfully collected user sys_id");
return true;
} else {
stepResult.setOutputMessage("Failed to collect user sys_id"); //This likely means that the group member record is bad
return false;
}
} else {
stepResult.setOutputMessage("Failed to find group members"); //This likely means that there are no group members
return false;
}

})(outputs, steps, stepResult, assertEqual);

 

The next step could be Impersonate where you will select the output from the above step as input to this. 

I tested this out and it correctly selected a member of the group that I had specified.

After that you can use this user as the approver of the Change Request in following steps. 

Hope this helps