- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2020 11:24 PM
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.
Solved! Go to Solution.
- Labels:
-
Customer Service Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2020 11:35 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2020 11:35 PM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2022 06:04 PM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 09:45 AM
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;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 09:45 AM
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;
}
}