- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 07:41 AM
HI Community,
In a catalog item there is a List collector variable i need to select only 10 options max....currently i can select multiple options but i need to select only 10.
How can we achieve this.
Thanks & Regards,
Suuriya Sridharan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 08:14 AM
Hi @suuriya ,
Please use this onChange client script, on change field would be the list collector field itself.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var selectedValues = g_form.getValue('<list_collector_name>').toString().split(',');
if (selectedValues.length > 10) {
alert('You can select a maximum of 10 values.');
g_form.clearValue('<list_collector_name>');
for (var i = 0; i < 10; i++) {
g_form.setValue('<list_collector_name>', selectedValues[i]);
}
return false;
}
}
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 08:00 AM
Hi @suuriya ,
Refer the below solved articles which may help you.
Please appreciate the efforts of community contributors by marking appropriate response as Mark my Answer Helpful or Accept Solution this may help other community users to follow correct solution in future.
Thanks
Ajay Kumar
Linkedin Profile:- https://www.linkedin.com/in/ajay-kumar-66a91385/
ServiceNow Community Rising Star 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2024 08:14 AM
Hi @suuriya ,
Please use this onChange client script, on change field would be the list collector field itself.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue) {
return;
}
var selectedValues = g_form.getValue('<list_collector_name>').toString().split(',');
if (selectedValues.length > 10) {
alert('You can select a maximum of 10 values.');
g_form.clearValue('<list_collector_name>');
for (var i = 0; i < 10; i++) {
g_form.setValue('<list_collector_name>', selectedValues[i]);
}
return false;
}
}
If you find my response helpful, please consider marking it as the 'Accepted Solution' and giving it a 'Helpful' rating. Your feedback not only supports the community but also encourages me to continue providing valuable assistance.
Thanks,
Amitoj Wadhera