Client Script not recognising data in Multi-Row Variable Set (MRVS)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Everyone,
I am struggling with an onSubmit Catalog Client Script that is intended to validate that at least one change has been requested before a user submits a "Distribution List" modification request.
The Goal: If the user selects "Change Existing Distribution List," they must fill out at least one of several fields OR add at least one row to a Multi-Row Variable Set (MRVS) named additional_dl_member_outside_dpc.
The Problem: Even when I add rows to the MRVS, the script still triggers the error message and prevents submission as if the MRVS were empty. I have verified the internal names and tried checking for '', [], and JSON.parse().length, but the script doesn't seem to "see" the new rows during the onSubmit event.
function onSubmit() {
var changeRequired = g_form.getValue('change_required');
var addNew = g_form.getValue('add_new_distribution_list_owners');
var removeO = g_form.getValue('remove_distribution_list_owners');
var addMembers = g_form.getValue('add_distribution_list_members');
var removeM = g_form.getValue('remove_distribution_list_members');
var outsideMembers = g_form.getValue('additional_dl_member_outside_dpc');
if (changeRequired == 'Change Existing Distribution List' && addNew == '' && removeO == '' && addMembers == '' && outsideMembers == '' && removeM =='') {
g_form.addErrorMessage('At least one distribution list must be specified before submitting.');
return false; // Prevent submission
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
try this
function onSubmit() {
var changeRequired = g_form.getValue('change_required');
var addNew = g_form.getValue('add_new_distribution_list_owners');
var removeO = g_form.getValue('remove_distribution_list_owners');
var addMembers = g_form.getValue('add_distribution_list_members');
var removeM = g_form.getValue('remove_distribution_list_members');
var outsideMembersRaw = g_form.getValue('additional_dl_member_outside_dpc');
var hasOutsideMembers = outsideMembersRaw !== '' && outsideMembersRaw !== '[]';
if (changeRequired === 'Change Existing Distribution List' &&
addNew === '' && removeO === '' && addMembers === '' &&
!hasOutsideMembers && removeM === '') {
g_form.addErrorMessage('At least one distribution list must be specified before submitting.');
return false;
}
}
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Ankur Bawiskar,
Thanks for your response!
Unfortunately, the outcome is still the same. Even when the MRVS has a row of data, the onSubmit script still triggers the error message as if it were empty.
I’ve double-checked the internal name and UI Type (All), but hasOutsideMembers is still returning false (or at least, the condition is still being met) even when rows are present.
Is there another approach to handle MRVS validation? For example, is there a way to check the actual row count of the MRVS object during onSubmit instead of comparing the string value of the variable?
Any further advice on how to deal with this specific MRVS behavior would be greatly appreciated!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
so only 1 MRVS is there and others are normal string variables?
you will have to debug where it's failing by adding alert
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
