push data in to json object
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 04:17 AM
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
where am i gone wrong?
Labels:
- Labels:
-
Scripting and Coding
6 REPLIES 6
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 05:13 AM
o the last reply would work for you, make an object and at the end just push it as json
-Anurag
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 05:28 AM
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);