List Collector

priyanka1028
Tera Contributor

Hello,

 

I want to set limit of choices 5 on list collector. 
How can we implement this any idea?

1 ACCEPTED SOLUTION

Samaksh Wani
Giga Sage
Giga Sage

Hello @priyanka1028 

 

You need to write a onSubmit() Catalog Client Script 

Applies to Catalog Item

Applies on Catalog Item view -  True

UI Type = ALL

 

 

function onSubmit()

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

if(values.length > 5){

alert('Please select only 5 choices');

return false;

}

}

 

 

Plz Mark my Solution as Accept and Give me thumbs up, if you find it helpful.

 

Regards,

Samaksh

 

 

View solution in original post

11 REPLIES 11

Pavankumar_1
Mega Patron

Hi @priyanka1028 ,

You can try below onchange catalog client script

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	var nameslist = g_form.getValue('user_names');//add your list collectorvariable name
	if(nameslist.length >5){
		g_form.clearValue('user_names');
		g_form.addErrorMessage("Please select only 5 choices");
	}
}

 

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

Harish Bainsla
Kilo Patron
Kilo Patron

function onLoad() {
var listCollectorField = g_form.getControl('list_collector_field_name'); // Replace with the actual field name
var maxChoices = 5; // Set the maximum number of choices you want to display

if (listCollectorField) {
var choices = listCollectorField.options;

if (choices.length > maxChoices) {
for (var i = maxChoices; i < choices.length; i++) {
choices[i].style.display = 'none';
}
}
}
}