Help with Limiting Number of Selections in a List field on sctask form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 12:51 AM
Hi,
I am trying to limit the selection by user on a list type custom field on sctask form with below Client script, but it removes all the options > it should only allow three selections and as soon as fourth is selected it would give the message and remove the fourth one:
function onChange(control, oldValue, newValue, isLoading) {
var check = g_form.getValue('u_dropdown').split(',');
if (check.length > 3) {
g_form.showFieldMsg('u_dropdown', 'Only three selection is permitted for this field');
g_form.setValue('u_dropdown', check[check.length-1]);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2022 12:57 AM
Hi,
don't remove any value as you will have to define logic to know which was the 4th one by comparing old and new value
just show the message near field
function onChange(control, oldValue, newValue, isLoading) {
var check = g_form.getValue('u_dropdown').split(',');
g_form.hideFieldMsg('u_dropdown');
if (check.length > 3) {
g_form.showFieldMsg('u_dropdown', 'Only three selection is permitted for this field','error');
}
}
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
06-23-2022 05:58 AM
Hi Ankur,
Thanks for the suggestion, however, just one query, this will still allow user to save the form with more than three selection (ignoring the message) - Thats why i was needing to remove the forth selection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2022 10:49 PM
Hi Sam,
That should still be fine.
You can inform the user and let user decide which value to be removed so that only 3 remains.
If my response helped please mark it correct and close the thread so that it benefits future readers.
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
06-27-2022 11:23 PM
@Sam
Hope you are doing good.
Did my reply answer your question?
If my response helped please close the thread by marking appropriate response as correct so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader