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

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

Can you try to use run server side validation script; query the sys_user table with active user with setLimit(5); push those 5 values in array and use output of this step in the next step

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

Thanks for the reply.  I have tried multiple variations, but just can't quite seem to get it to work.  It isn't returning anything.

Here is my script:

(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.sys_id);
		//users.push(gr.getValue('sys_id'));
		//users.push(gr.name);
	}
	
	//return string of users
	return users;
	//return JSON.stringify(users);
		
})(outputs, steps, stepResult, assertEqual);

You can see from the lines I have commented out, I have tried different variations, but none seem to work.  None seem to populate my user field with anything when I try to assign the result from this step to that user field variable.

Can you seem what I am doing wrong?

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

Hi,

Recently I have published a blog related to this; please check the link and mark as helpful

https://community.servicenow.com/community?id=community_blog&sys_id=3d94d51cdb8cd4d823f4a345ca96198a

Regards
Ankur

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