ATF: Selecting Multiple Dynamic Users in Service Portal Form

jmiskey
Kilo Sage

In building out our ATFs, I have come across something I am not sure how to do.  In some of our Catalog Items, we allow them to enter multiple users.  When creating an ATF, usually when setting the variable values, when setting a field that allow multiple entries, you separate them with a comma.  If we were selecting specific users from the user table, this would work fine.  However, in the interest of keeping our ATF testing dynamic, we do not wish to "hard-code" specific users in our testing.  We would like to either query the user table for active users, or create users to use for testing.

So, in my test, I did one of each (Record Query to query active users and Create a User).  It was my hope that then when I was populating my user field on my Catalog Item, I would be able to select each of these.  But that does not appear to be the case.  It looks like if you select a user from a previous step, there doesn't appear to be a way to select another user.

This is what it looks like (the first field is my user field):

find_real_file.png

So, is there any way to select multiple dynamic users in an ATF test on the Service Portal?

Thanks

 

1 ACCEPTED SOLUTION

Hi,

I was able to set the values dynamically using Run Server Side Script

please update code as below in the script; see screenshot as well

Ensure you determine this and then open the catalog item and then set the values

(function(outputs, steps, stepResult, assertEqual) {
    
	//set up array for output
	var users = [];
	
	// pull out first 2 active members of sys_user table
	var gr = new GlideRecord('sys_user');
	gr.addQuery('active','true');
	gr.setLimit(2);
	gr.query();
	
	//build array of two users to output
	while(gr.next()){	
		users.push(gr.getValue('sys_id'));
	}
	
	outputs.table = 'sys_user';
	outputs.record_id = users.toString();

        stepResult.setOutputMessage("Successfully collected users " + users.toString());
	stepResult.setSuccess();
	return true;
		
})(outputs, steps, stepResult, assertEqual);

find_real_file.png

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

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

View solution in original post

10 REPLIES 10

Hi,

Any update on this?
Can you mark my answer as correct, 👍 helpful if you were able to achieve the requirement. This enables other members to learn from this thread.

Regards
Ankur

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

Sorry, I typically do not work over the weekends, so am just getting back to this now on Monday.  Yes, that works, thank you very much.

It has kind of presented a new challenge though.  After these transactions are submitted via the Service Portal, I am then continuing the ATF testing by working on them after the RITMs have been created.  The first step in the Workflow is Manager approval.  So I would need to dynamically impersonate the managers of those dynamic users we selected above in order to do the approvals.  I have a feeling that is going to be another Server Side Script.  Maybe we look up the Approver off of the RITMs that are created?  Not really sure the best way to go about that.

Hi,

you can have server side script and query the approval table for this RITM which got created in previous step and then determine the approver user; store in the record_id variable

you can then use that in impersonate step

Regards
Ankur

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

Got it.  Thank you.

Ramakrishna Ch1
Kilo Explorer

Hi,

You got solution for multiple dynamic users?