How to limit the list collector choices selection

Sai Akhil
Tera Contributor

Hi All,

I have a requirement where I am using a variable as a list collector in a catalog item,  where users can select up to 3 choices if they exceed the limit then they should populate the message that the limit is exceeded. please let me know how to achieve this.

Thanks in advance,

Akhil.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

write onSubmit catalog client script

Applies to Catalog Item

Applies on Catalog Item view -  True

UI Type = ALL

Note: give your list collector variable name below

function onSubmit()

var values = g_form.getValue('variableName').toString().split(',');

if(values.length > 3){

alert('Please select only 3 choices');

return false;

}

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

write onSubmit catalog client script

Applies to Catalog Item

Applies on Catalog Item view -  True

UI Type = ALL

Note: give your list collector variable name below

function onSubmit()

var values = g_form.getValue('variableName').toString().split(',');

if(values.length > 3){

alert('Please select only 3 choices');

return false;

}

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

When I copied and pasted the entire code, I found I needed to add a { on line 2.  Otherwise it works great.  Thank you!

function onSubmit()
{
var values = g_form.getValue('variableName').toString().split(',');

if(values.length > 3){

alert('Please select only 3 choices');

return false;

}

}

HI Anukar,

 

I am write same code in OnChange also it's works but i got problem here it will add 6th record also Then how can i delete or remove latest record 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below

var values = g_form.getValue('who_are_need_to_access').toString().split(',');
    //g_form.addInfoMessage('total value in users '  + values);

if(values.length > 5){

alert('Please select only 5 choices');
    //g_form.removeOption('who_are_need_to_access','value');

return values;

}
   
}

HI Anukar,

 

I am write same code in OnChange also it's works but i got problem here it will add 6th record also Then how can i delete or remove latest record 

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   //Type appropriate comment here, and begin script below

var values = g_form.getValue('who_are_need_to_access').toString().split(',');
    //g_form.addInfoMessage('total value in users '  + values);

if(values.length > 5){

alert('Please select only 5 choices');
    //g_form.removeOption('who_are_need_to_access','value');

return values;

}
   
}