onChange script error: ReferenceError: 'g_list' is undefined function

kedler
Kilo Guru

Hi all,

I need help with an error I am receiving.

onChange script error: ReferenceError: 'g_list' is undefined function h_35f58dc2dbca2b4055e8750b8c9619c3(control, oldValue, newValue, isLoading)
 
Here is my script:
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
    }
}
1 ACCEPTED SOLUTION

I actually just needed to only apply the script to the catalog item view, and not to the Requested item. Thanks!

View solution in original post

3 REPLIES 3

Brian Lancaster
Tera Sage

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

I actually just needed to only apply the script to the catalog item view, and not to the Requested item. Thanks!