How to get Multi-row variable set of variable values into JSON

chanikya
Kilo Sage

Hi All,

Please help me on below issue .

How to get Multi-row variable set of All variable values details. Some variables details missing in JSON which were not filled by user (empty variables ) .

Issue : On Catalog-item i have added 3- row details  like below

Using with below Client-script I m trying to get 3-rows of variables details  in JSON format. 3-rows of JSON format.

find_real_file.png 

MRVS  has around 25-variables. if you see above screenshot Prod variable are checkboxe , i made Prod checkbox : true for one-row only , in rest of  2-rows of Prod variable value is false.

 

i can see Prod: true only one time in total 3-rows of JSON , but why not it showing  Prod:false in remaining 2-times.  At-least variable /variable value has to show as Prod:false in next 2-rows of JSON format right,  but here complete variable not at all showing in next 2-JSON lines.

 

Client script : OnSubmit

var value = g_form.getValue("IO:a0c19722dbe45450c38babc5ca96191b");
alert(value);

 

[{"server_name":"","dev_server":"","name_1":"5ad4a5fb1bbb2410f2e7ecadee4bcbc4","test_server":"","operational_status":"7","app_ci_dev":"","app_ci_qa":"","itglt_owner":"287b5a271b573700d849ed776e4bcb0b","description":"Qt Creator provides a cross-platform, complete integrated development environment (IDE) for application developers to create applications","go_live_date":"","install_type":"","qa":"false","dev":"false","app_ci_prod":"c7e159aa1b85781cf2e7ecadee4bcb1b","app_ci_test":"","server_not_found":"false","save_business_chb":"true","prod":"true","IO:089f6a7edb9689d00289818a139619e7":"false","test":"false","IO:009f6a7edb9689d00289818a139619e8":"true","primary_bpo":"bc985e231bd33700d849ed776e4bcba0","qa_server":"","IO:889f6a7edb9689d00289818a139619e7":"false","IO:8c9f6a7edb9689d00289818a139619e7":"false","review_date":"03/21/2022","IO:849f6a7edb9689d00289818a139619e7":"false","IO:0c9f6a7edb9689d00289818a139619e7":"false","primary_system_owner":"3b59d62b1bd33700d849ed776e4bcbf0","prod_server":""},
{"actions":"","name_1":"5b5c30fa1b79e01036e80ed6624bcb66","operational_status":"7","go_live_date":"","description":"AWS CodeArtifact is a fully managed artifact repository service that makes it easy for organizations of any size to securely store, publish, and share software packages used in their software development process.","itglt_owner":"981dc2a71b933700d849ed776e4bcb4d","primary_system_owner":"3b59d62b1bd33700d849ed776e4bcbf0","primary_bpo":"677b16671b573700d849ed776e4bcb5c","primary_so":"3b59d62b1bd33700d849ed776e4bcbf0","install_type":""},
{"actions":"","name_1":"5b78a03ddb0f2450405c9f67f4961991","operational_status":"7","go_live_date":"","description":"Medical Products General Web Portal","itglt_owner":"981dc2a71b933700d849ed776e4bcb4d","primary_system_owner":"3b59d62b1bd33700d849ed776e4bcbf0","primary_bpo":"3b59d62b1bd33700d849ed776e4bcbf0","primary_so":"3b59d62b1bd33700d849ed776e4bcbf0","install_type":""}]

 

how to get all variables details ?

 MVRS has 25 variables means , 3 rows i added , so JSON must have 25 variables details in 3-times.

 

15 REPLIES 15

Hi,

you know the total rows as you are parsing the JSON

compare it against the count of true value

if not same then stop form submission

Regards
Ankur

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

Hi Ankur,

i tried to achieve using with below script , but not sure it is not working. Can you provide any help .

function onSubmit() {

var value = g_form.getValue("IO:a0c19722dbe45450c38babc5ca96191b");
alert('JSON is ' + value);

var arr = [];
var parser =JSON.parse(g_form.getValue("IO:a0c19722dbe45450c38babc5ca96191b"));
var length = parser.length;
alert("Length :" + length);


for (var i = 0; i < parser.length; i++) {
arr.push(parser[i].prod.toString());
}
alert("Array Length :" + arr.length);
if (length == arr.length) {
return true;
} else {
alert("Please Mark review completed");
return false;
}


}

 Or-------------------

function onSubmit() {
//Type appropriate comment here, and begin script below
//var value = g_form.getValue('business_application_table_data');
var value = g_form.getValue("IO:a0c19722dbe45450c38babc5ca96191b");
alert('JSON is ' + value);

var arr = '';
var parser= JSON.parse(g_form.getValue('IO:a0c19722dbe45450c38babc5ca96191b'));
var length = parser.length;
alert("Length :" + length);


for (var i = 0; i < parser.length; i++) {
var aa = parser[i].prod.toString();
arr = aa.join();
alert("Array Length :" + arr.length + "--" + arr);
alert("Array Length :" + arr.length);
if (length == arr.length) {
return true;
} else {
alert("Please Mark review completed");
return false;
}
}

 

 

}

Hi,

update as this

function onSubmit() {
	//Type appropriate comment here, and begin script below

	var parser= JSON.parse(g_form.getValue('business_application_table_data'));
	var length = parser.length;
	var count = 0;
	for (var i = 0; i < parser.length; i++) {
		var aa = parser[i].prod.toString();
		if(aa == 'true')
			count++;
	}
	if(count != length){
		alert("Please Mark review completed");
		return false;
	}

}

Regards
Ankur

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

Hi Ankur,

Sorry , code not working

getting error like java browsing error , and submitting form.

 

Hi,

did you add alert to check count for both?

what's the browser console error?

Regards
Ankur

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