- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2023 10:43 PM
Hello,
I want to set limit of choices 5 on list collector.
How can we implement this any idea?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2023 11:06 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2023 11:43 PM
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");
}
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2023 12:17 AM
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';
}
}
}
}