get MVRS values in catalog client script

marcn
Tera Expert
 var mvrsvalues= JSON.parse(g_form.getValue('mvrs_name'));

g_form.addInfoMessage(mvrsvalues)

is it not possible to get mvrs json in catalog client script ?

 

I'm just trying to log the json string and it doesnt work, trying in onchange of a variable of MVRS using catalog client script for a catalog item

11 REPLIES 11

Harish KM
Kilo Patron
Kilo Patron

Hi refer the links below

https://community.servicenow.com/community?id=community_article&sys_id=2a508caedbf47f48d82ffb243996198f

https://community.servicenow.com/community?id=community_question&sys_id=37c35df8dbb6d850fb115583ca96195e

Regards
Harish

Mohith Devatte
Tera Sage
Tera Sage

Hello @marcn ,

Yes 

try below  script

var mvrsvalues= JSON.parse('mvrs_name');
g_form.addInfoMessage(JSON.stringify(mvrsvalues)); // to print the JSON


//Below code is to access the JSON elements
 for(var i=0; i<mvrsvalues.length;i++)

{

g_form.addInfoMessage(mvrsvalues[i].your_variable_name_in_mvrs);

}

Please mark my answer correct if it helps you

@marcn  thanks for marking my answer helpful and please mark my answer correct if it helped you so that it will be removed from unsolved list.

And for you question to compare two values you can use below script

But change you script to on submit in on change you cant do it

function onSubmit() {
    var value = g_form.getValue("your mvrs name"); 
    var mvrsArr = JSON.parse(value);

    var comparedValue = compareValues(g_form.getValue("your column variable back end name to check "), mvrsArr)) 
 alert(comparedValue);
   
    
}

function compareValues(valueToBeChecked, mutiRowArray) {
    for (var i = 0; i < mutiRowArray.length; i++) {
        if (mutiRowArray[i].your_variable_back_end_name == valueToBeChecked) { 
            return 'valueFound';
        }
    }
}

 

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can access complete JSON of MRVS only in onChange or onSubmit catalog client script which applies to either Catalog item or a variable set(not MRVS)

You cannot access complete JSON if you are writing onChange script on 1 of the variable within MRVS

Regards
Ankur

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