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

Hi @Narra Ramakotes ,

Below the code for Removing the last 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').split(',');
    //g_form.addInfoMessage('total value in users '  + values);

if(values.length > 5){
g_form.clearMessage();
values.pop() // remove the last record
 g_form.setValue("DL_Members", Members.join());
g_form.addErrorMessage('Please select only 5 choices');
}
   
}

 

dub
Kilo Contributor

I get an unexpected token var error