Validation Script for Multi-Row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 02:09 PM
Hi,
I need to add the validation script on multi-row variable set which will validate the value in the single line text and restrict user to add the row in MRVS. I tried below Catalog Client Script but it is not working
Applies to - A variable set
Type = OnSubmit
function onSubmit() {
var msg = 'You cannot enter a single or double quote or a backslash';
var mrvs = g_form.getValue('IO:0c5fb747db2b8c102cb804c2ca9619d5');
//var mrvs = JSON.parse(g_form.getValue('test_mrvs'));
for(var i=0;i<mrvs.length;i++)
{
if (!isValid(mrvs[i].test_variable)) {
g_form.addErrorMessage(msg);
return false;
}
}
}
function isValid(text) {
var IsValidChar = true;
if (text == null) return;
if (text.indexOf('"') > -1 || text.indexOf('\\') > -1 || text.indexOf('\'') > -1) {
IsValidChar = false;
}
return IsValidChar;
}
- Labels:
-
User Experience and Design

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 02:11 PM
Check below blog for MVRS scripting
https://community.servicenow.com/community?id=community_blog&sys_id=865b5aeddbc023c0feb1a851ca9619f9
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 02:30 PM
Hi Sachin,
This post does not have the use case I am trying to achieve. I want to put the validation before the user will add the row in the MRVS and it seems The script I used is not working on the Add button on the popup. I want to restrict user to add the row if the data is not valid. I know we can do it onSubmit script of catalog but for the better user experience, I am trying to do it while the user is adding the rows.
Thanks,
Ankit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 02:34 PM
I usually do this with an onChange script, as opposed to an onSubmit. The onChange runs on the variable you need to validate, on the variable set not the item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-30-2020 02:37 PM
I tried with the onChange as well but it seems that even there is an error in the MRVS pop-up but it still allows you to click on the Add button and add rows. It is not restricting user to add rows if there are any error on the popup.