- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 08:09 PM
Hi Guys,
I have a requirement to setup a script to verify user needs to fill in minimum 4 records in MRVS. Not sure how to write on the client script? I tried below one but it doesn't work.
function onSubmit() {
//Type appropriate comment here, and begin script below
if(g_form.getValue('list_authorized_signatories_four_signers_minimum') < '4'){
g_form.alert('You must enter at least 4 signers');
return false;
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 08:56 PM
Hi Bird,
Following script will show an error message when there is less than 4 rows in mrvs field named "list_authorized_signatories_four_signers_minimum".
Number of rows is an integer so should compare with integer 4 and not string '4'
To display an error message, use g_form.addErrorMessage(). There is no such method as g_form.alert().
function onSubmit() {
var mrvs = g_form.getValue('list_authorized_signatories_four_signers_minimum');
var jsonMrvs = JSON.parse(mrvs);
if (jsonMrvs.length < 4) {
g_form.addErrorMessage('You must enter at least 4 signers');
return false;
}
}
Execution example output.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 08:37 PM
Hey,
Please try below code to get length of MRVS
var mrvs = g_form.getValue('list_authorized_signatories_four_signers_minimum');
var parsedMRVS = JSON.parse(mrvs);
var lengthMRVS = parsedMRVS.length// you can now check whether min 4 rows are there or not
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 08:45 PM
Hi,
you cannot check for minimum but you can check for maximum rows
No script required; You can use UI policy to make that MRVS mandatory
Steps
1) add a UI Policy without any conditions (so that it runs onLoad) which applies on catalog item
2) Then add a UI Policy Action where you select the Multi Row Variable Set name within the Variable Name field
Select the MRVS from variables field
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-13-2022 08:56 PM
Hi Bird,
Following script will show an error message when there is less than 4 rows in mrvs field named "list_authorized_signatories_four_signers_minimum".
Number of rows is an integer so should compare with integer 4 and not string '4'
To display an error message, use g_form.addErrorMessage(). There is no such method as g_form.alert().
function onSubmit() {
var mrvs = g_form.getValue('list_authorized_signatories_four_signers_minimum');
var jsonMrvs = JSON.parse(mrvs);
if (jsonMrvs.length < 4) {
g_form.addErrorMessage('You must enter at least 4 signers');
return false;
}
}
Execution example output.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-13-2022 09:35 PM
Awesome! It's workable.