- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2018 07:04 AM
Hi all,
I need help with an error I am receiving.
function onChange(control, oldValue, newValue, isLoading) {
//Limit the number of selected options in a list collector
//Specify the max options/max number of jobs and variable name below
var maxOptions = 3;
var jobCollector = 'job_names';
var myListCollector = g_list.get(jobCollector);
var selectedOptions = g_form.getValue(jobCollector).split(',');
if(selectedOptions.length > maxOptions){
//Remove the last item
myListCollector.removeItem(selectedOptions[selectedOptions.length-1]);
g_form.addErrorMessage('You cannot select more than ' + maxOptions + ' jobs.');//Error message
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2018 07:55 AM
I actually just needed to only apply the script to the catalog item view, and not to the Requested item. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2018 07:36 AM
Hi,
Check below links.
Uncaught ReferenceError: g_list is not defined
g_list does not work on List Link UI actions
Regards,
Devyani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2018 07:43 AM
Do you even need a g_list in your code. You could probably just change it to this.
function onChange(control, oldValue, newValue, isLoading) {
//Limit the number of selected options in a list collector
//Specify the max options/max number of jobs and variable name below
var maxOptions = 3;
//var jobCollector = 'job_names';
var myListCollector = 'job_names';
var selectedOptions = g_form.getValue('job_names').split(',');
if(selectedOptions.length > maxOptions){
//Remove the last item
myListCollector.removeItem(selectedOptions[selectedOptions.length-1]);
g_form.addErrorMessage('You cannot select more than ' + maxOptions + ' jobs.');//Error message
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2018 07:55 AM
I actually just needed to only apply the script to the catalog item view, and not to the Requested item. Thanks!