How to set 'minimum' row requirement of MRVS?

Bird1
Mega Sage

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;
}
}

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

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.

find_real_file.png

View solution in original post

9 REPLIES 9

Aman Kumar S
Kilo Patron

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

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

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

find_real_file.png

Select the MRVS from variables field

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hitoshi Ozawa
Giga Sage
Giga Sage

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.

find_real_file.png

Awesome! It's workable.