- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 01:04 AM
I have a List Collector Variable, In this I want to restrict the selection of number of choices to two only. So, that user can able to select two options only. How to Perform this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 01:23 AM
I can see OnChange
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 01:23 AM
I can see OnChange
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 01:34 AM
thats great its working! but there is problem. After selection of third option i am getting alert box and at the same time the 3rd option was also selecting so, i want to remove that selections after the alert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 01:39 AM - edited ‎01-29-2024 01:42 AM
use g_form.removeOption(<fieldName>, <choiceValue>); get the choice value from the new value variable OR
use the code in this answer https://www.servicenow.com/community/itsm-forum/remove-just-single-value-from-selected-values-in-a-l...
Regards,
Piyush Sain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 02:03 AM
The values are Not Clearing @piyushsain.
I am getting that alert that's all.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2024 01:39 AM
Hi @Aditya02
Try below On-Change Client Script :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var values = g_form.getValue('requested_for').toString().split(',');
var listCollector = g_list.get('requested_for');
var selectedOptions = g_form.getValue('requested_for').split(',');
if (values.length > 2) {
alert('Please select only 2 values');
var index = 0;
for (var i = 1, leng = values.length + 1; i < leng; i++) {
listCollector.removeItem(selectedOptions[selectedOptions.length - i]);
index++;
}
}
}
Thanks & Regards
Amit Verma
Please mark this response as correct and helpful if it assisted you with your question.