The CreatorCon Call for Content is officially open! Get started here.

Get MVRS Value From JSON

Piyush27
Tera Contributor

Hi All,

 

I have written an onSubmit code to get the number of rows inserted into MVRS (multi-row variable set).

var mvrsValue = g_form.getValue('questions');

if(mvrsValue){//if it has a value

var jsonObj = JSON.parse(mvrsValue);

console.log('There are ' + jsonObj.length + ' rows); }

else { // if i recall correctly, .getValue returns null if empty

console.log('No Rows'); }

 

When I run this I get 

 

[{
"order": "100",
"question": "What do you need help with?",
"required": "Yes",
"help_text": "test"
}]

 

Now I want to get the value from this.

For example--

What is the value of order and required

 

Thanks,

Piyush Kumar

 

 

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @Piyush27 

 

Try the following code.

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var mvrsValue = g_form.getValue('questions');
    if (mvrsValue) {
        var jsonObj = JSON.parse(mvrsValue);
		for(key in jsonObj){
			console.log('Order: ' + jsonObj[key].order + ', Required: ' + jsonObj[key].required);
		}


        console.log('There are ' + jsonObj.length + ' rows');
    } else { // if i recall correctly, .getValue returns null if empty
        console.log('No Rows');
    }

}

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh

View solution in original post

1 REPLY 1

AnveshKumar M
Tera Sage
Tera Sage

Hi @Piyush27 

 

Try the following code.

 

function onSubmit() {
    //Type appropriate comment here, and begin script below
    var mvrsValue = g_form.getValue('questions');
    if (mvrsValue) {
        var jsonObj = JSON.parse(mvrsValue);
		for(key in jsonObj){
			console.log('Order: ' + jsonObj[key].order + ', Required: ' + jsonObj[key].required);
		}


        console.log('There are ' + jsonObj.length + ' rows');
    } else { // if i recall correctly, .getValue returns null if empty
        console.log('No Rows');
    }

}

 

Please mark my answer helpful and accept as solution if it helped you 👍✔️

Thanks,
Anvesh