- 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-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
‎12-08-2020 04:31 AM
Hello David,
I'm facing the same issue in one of my catalog item where I've to set the list collector variable value from glide_list field of sys_user table. It works until the list has 30 items and if it crosses the display value is not set. Have you anytime raised this issue with ServiceNow?