- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2018 04:05 PM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 11:22 AM
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];
}
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 11:08 AM
Thanks Sanjiv, you are correct that if I manually select more than 30 records it allows it.
I tried hardcoding the comma separated list of all the reports into the server script and it did NOT work.
Not sure where the limitation is happening, somehow it seems if you are writing enough data to a list collector using g_form.setValue it breaks?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 12:14 PM
If you convert the comma separated list to an array and then to a setValue()?
For ex.
var test_lc = 'a,b,c,d,e,f';
var test_lc_arr = test_lc.split(',');
g_form.setValue('list col variable',test_lc_arr);
Also is all the ysids passed are active users?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 01:33 PM
I just tried converting it to an array, still doesn't work.
All the users that are returned should be active if that makes a difference. To double check I added a query for active=true and I'm still getting the same issue.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-03-2018 01:54 PM
Can you try implementing the solution mentioned in below thread. Moving them one by one may work
https://www.servicenowguru.com/scripting/client-scripts-scripting/move-list-collector-options/
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2018 08:38 AM
Thanks Sanjiv, but I'm looking at this for the Service Portal using a widget as the button, the code + behavior in the links there doesn't apply to list collectors on the service portal (there are no left and right buckets).