push data in to json object

rick48
Tera Contributor

need to push the data into json object and store it in a variable

function executeRule(current, previous /*null when async*/) {

	var fields = current.getFields();
	var sysid=current.sys_id;
	var json={};
	
	var hits = [];
	var value=[];
	var field=[];

		for (var i = 0; i < fields.size(); i++) {
			var glideElement = fields.get(i);
			if (glideElement.hasValue()) {
				field.push(glideElement);
				value.push(glideElement.getName());
				hits.push(glideElement.getName() + ':' +glideElement);
				json.push(glideElement.getName() + ':' +glideElement);
		}
	}


var temp = JSON.stringify(json);
gs.log(temp,"jidesh");
	hits.push("sys_id" + ":" + sysid);
	
//
})(current, previous);

tried above script but it didn't work

in logs its getting as below

find_real_file.png

where am i gone wrong?

6 REPLIES 6

o the last reply would work for you, make an object and at the end just push it as json

-Anurag

 i think in the above script i have already pushed the fields and values to the json

var json={};

for (var i = 0; i < fields.size(); i++) {
			var glideElement = fields.get(i);
			if (glideElement.hasValue()) {
				field.push(glideElement);
				value.push(glideElement.getName());
				hits.push(glideElement.getName() + ':' +glideElement);
				json.push(glideElement.getName() + ':' +glideElement);
		}
	}


var temp = JSON.stringify(json);