Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

Brilliant solution! Thank You!

Harish KM
Kilo Patron
Kilo Patron

Can try this.

Script:

function onSubmit() {

var a = g_form.getValue('demo_multi_vars'); //internal name of variable set

var obj = JSON.parse(a);
var rows = obj.length;
alert(rows);
if (rows <=4)
{
alert("need to submit 4 rows");
return false;
}

}

find_real_file.png

Regards
Harish

Hi All,

 

I wrote the same code, but it is not working. 

Can you pelase check the issue:

function onSubmit() {
    var bulk = g_form.getValue('is_this_a_bulk_request_for_than_5_account');
    var mrvs = g_form.getValue('user_details_bulk'); //mrvs1
    var mrvs2 = g_form.getValue('user_details_remove_bulk'); //mrvs2
    var parser = JSON.parse(mrvs);
    var parser2 = JSON.parse(mrvs2);

        if(parser.legth < 2 || parser2.length < 2)
        {
        g_form.addErrorMessage('Oops, you have submitted a bulk request for 1 user.  Please either add additional users; or if your request is for 1 user, select the option of "1 account".');
        return false;
        }
}

@Kritika1 

Can you please raise a new question as this is an old thread and tag me there?

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