- 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:31 AM
OK, reading again what you are trying to accomplish, let me clarify to make sure:
On a GlideList variable, you want to validate that the number of selections does not exceed a given amount.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 08:32 AM
Yes sir!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 08:44 AM
Since you indicated this will be an onChange Catalog Client script, we can leverage the value of newValue which may be more efficient. This way you can use the list field in your onChange script for validation. Feel free to adjust accordingly.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var chkArray = newValue.toString().split(',');
if (chkArray.length > 5) {
alert("You cannot select more than 5 entries at a time");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2017 09:33 AM
Hi Christopher,
You/We are almost close.. But the issue is even users after 5 are being added.
I tried
chkArray.pop();
and return false;
Either of them didnt work..

- 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.