push data in to json object
- 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:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 04:30 AM
Add everything in your arraye and then you can encode it into json as below
new global.JSON().encodeArray(<your array>);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 04:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 05:03 AM
Ok, the simpler way
var myObj={}
myObj.name='AAA';
myObj.title='BBB';
myObj.something='CCC'l
var json = new JSON();
var result = json.encode(myObj);//JSON formatted string
Please mark my answer correct/helpful if it helped you solve your issue.
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 05:08 AM
since i cant get all the fields and values from incident table i just used a forloop and tried to push it to the json.
it need to be pushed dynamically.