How to increase the maximum size of a list collector?

david_williams1
Kilo Expert

Hey folks,

We have an item for users to request a new distribution group on our service portal, which includes a list collector on the users table to specify which users should be added to the group.

I'm setting up a button so that managers can add all users who report to them to the variable with one click. As this is service portal, I'm using a macro variable which points at a widget to do the work. Server side gets the list of users with a recursive function, then client side writes it into the variable on the form. It's working well in most cases, but when I try it on a user with a lot of reports (more than about 30), the script doesn't seem to be able to write to the list collector variable. For testing I wrote it to a multi-line text variable and it's coming up with a comma seperated list of however many user sysIDs it's supposed to have, no problems there.

Managers with fewer reports are also working fine, so I feel like this is an issue with a maximum length limitation on the list collector field (30 users is around the 1000 character mark). Just wondering where to go to increase the maximum size, if it's possible.

Any help would be appreciated.

1 ACCEPTED SOLUTION

david_williams1
Kilo Expert

Hey Everyone,

I managed to figure this out. This thread was helpful

The issue appears to be some kind of limitation in using setValue on a service portal list collector, if you are assigning more than 30 values it doesn't generate the display value automatically and the code fails. The solution is to explicitly set the display value to another comma separated list of names which needs to be generated at the same time as getting the list of sysids.

When explicitly setting the display value list using setValue(field, value, displayvalue) with value being the comma separated list of sysids and displayvalue being the comma separated list of names, everything works as intended.

My final working server code is below, hopefully it will help someone in the future.

(function() {
	if (input && input.action) {
		var action = input.action;
 
			if (action == 'direct') {
				gr = new GlideRecord('sys_user');
				gr.addQuery('manager',gs.getUserID());
				gr.addActiveQuery();
				gr.query();
				var users = [];
				var usernames = [];
				while (gr.next()){
					users.push(gr.getValue('sys_id'));
					usernames.push(gr.getDisplayValue('name'));
				}
				data.field = options.field;
				var people = "";
				var names = "";
				for (var i=0;i<users.length; i++){
					people += users[i];
					people += ",";
					names += usernames[i];
					names += ",";
				}
				data.people = people;
				data.names = names;
			}
			if (action == 'all') {
				var results = getReportsRecursive(gs.getUserID());
				var allReports = results[0];
				var allnames = results[1];
				var people2 = "";
				var names2 = "";
				for (var j=0;j<allReports.length; j++){
					people2 += allReports[j];
					people2 += ",";
					names2 += allnames[j];
					names2 += ",";
				}
				data.field = options.field;
				data.people = people2;
				data.names = names2;
			}
	}
	
	function getReportsRecursive(user){
		gr = new GlideRecord('sys_user');
		gr.addQuery('manager',user);
		gr.addActiveQuery();
		gr.query();
		var users = [];
		var names = [];
		var count = gr.getRowCount();
		while (gr.next()){
			users.push(gr.getValue('sys_id'));
			names.push(gr.getDisplayValue('name'));
		}
		for (var i=0; i<count; i++){
			var results = getReportsRecursive(users[i]);
			var reports = results[0];
			var reportnames = results[1];
			for (var j=0; j<reports.length; j++){
				users.push(reports[j]);
				names.push(reportnames[j]);
			}
		}
		return [users,names];
	}
 
})();

View solution in original post

16 REPLIES 16

david_williams1
Kilo Expert

Nobody?

SanjivMeher
Kilo Patron
Kilo Patron

I don't think there will be a size issue.

Can you post the server script you are using to pull the sysids. Confirm if they are comma separated.


Please mark this response as correct or helpful if it assisted you with your question.

Thanks for the reply. The reason I think it's a size issue is if I limit it to only returning 30 users it works fine with no other changes, but when it returns all users it fails. Here's the server code.

There are two buttons on the widget, one for only direct reports and one for getting all reports recursively. If I use the commented out line to limit it to the first 30 users only, then the script works fine. I have also verified that even when returning all users it is correctly generating a comma separated list by writing it to a multi-line text field.

(function() {
	if (input && input.action) {
		var action = input.action;
 
			if (action == 'direct') {
				gr = new GlideRecord('sys_user');
				gr.addQuery('manager',gs.getUserID());
				gr.query();
				var users = [];
				while (gr.next()){
					users.push(gr.getValue('sys_id'));
				}
				data.field = options.field;
				var people = "";
				for (var i=0;i<users.length; i++){
					people += users[i];
					people += ","
				}
				data.people = people;
			}
			if (action == 'all') {
				var allReports = getReportsRecursive(gs.getUserID());
				var people2 = "";
				for (var j=0;j<allReports.length; j++){
				//for (var j=0; j<30; j++){
					people2 += allReports[j];
					people2 += ","
				}
				data.field = options.field;
				data.people = people2;
			}
	}
	
	function getReportsRecursive(user){
		gr = new GlideRecord('sys_user');
		gr.addQuery('manager',user);
		gr.query();
		var users = [];
		var count = gr.getRowCount();
		while (gr.next()){
			users.push(gr.getValue('sys_id'));
		}
		for (var i=0; i<count; i++){
			var reports = getReportsRecursive(users[i]);
			for (var j=0; j<reports.length; j++){
				users.push(reports[j]);
			}
		}
		return users;
	}
 
})();

If you don't apply a script on the list collector and manually select more than 30 records, it should allow. That's why I don't think it should be an issue with length.

 

Also Try hardcoding the Comma separated sys id if all the reportee using a script and see what happens.


Please mark this response as correct or helpful if it assisted you with your question.