- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 07:54 AM
Hi All,
I am trying to restrict the number of records which can be selected in a glide list to be 5.
I can best figure out that if i can operate something similar to an array concept i can restrict the selection and alert.
My interest is particularly in glide list, as I dont want to show all the user's name at start.
Piece of my code is
var maxOptions = 5;
var selectedIDs = [];
var str= selectedIDs.push(g_form.getValue('users'));
alert(str);
alert(str.length); //i know it would store a single string with multiple commas using this code
var index = 0;
for(var i = maxOptions; i < str.length; i++){
selectedIDs[index] = i;
index++;
}
Kindly advice me on my code or any better approach..
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 10:32 AM
This may work better as an onSubmit rather than an onChange. That way users can remove those list choices they deem unnecessary rather than relying upon the script to remove all but the first 5 entries. I am using list_variable as the variable name in my example:
function onSubmit() {
g_form.hideFieldMsg('list_variable', true);
var chkString = g_form.getValue('list_variable');
var chkArray = chkString.split(',');
if (chkArray.length > 5) {
var eMessage = 'You cannot select more than 5 entries at a time';
g_form.showFieldMsg('list_variable', eMessage, 'error');
return false;
}
}
Let me know if this is more successful since I have not tested it.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 08:00 AM
There are several built in functions that let you configure your GlideList. Take a look at the setRowsPerPage() function:
http://wiki.servicenow.com/index.php?title=GlideList2_(g_list)#setRowsPerPage
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 08:10 AM
Hi Christopher,
I am building a onChange script to perform the job as this is a catalog item..
Can the solution provided by you work in client side?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 08:26 AM
I have used g_list as a way of setting a filter on the list in the portal using a client script. Was thinking that the information contained would be helpful. Here is an example I found for catalog:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 08:31 AM
Thanks..I am not setting the filter but restricting the number of selections