how to pass the records in json?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 02:00 AM
i used the below script where it pass the data in an aray,i need to push to an json array.
(function executeRule(current, previous /*null when async*/) {
try {
var r = new sn_ws.RESTMessageV2('direct_rest_transaction', 'direct_rest_transa');
var fields = current.getFields();
var hits = [];
var name=[];
var field=[];
var sysid=current.sys_id;
for (var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
name.push(glideElement);
field.push(glideElement.getName());
hits.push(glideElement.getName() + ":" + glideElement);
}
}
hits.push("sys_id:" +sysid);
r.setStringParameterNoEscape("pay",hits);
r.setStringParameterNoEscape('name', name);
r.setStringParameterNoEscape('fields', field);
//r.setStringParameterNoEscape('type',1);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
})(current, previous);
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 02:44 AM
Hi,
See this link:
https://community.servicenow.com/community?id=community_question&sys_id=a4f847a1db5cdbc01dcaf3231f961950
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 03:03 AM
When i used global.json() its passing only the object
var hits = {};
var name={};
var field={};
var sysid=current.sys_id;
for (var i = 0; i < fields.size(); i++) {
var glideElement = fields.get(i);
if (glideElement.hasValue()) {
name.push(glideElement);
field.push(glideElement.getName());
hits.push(glideElement.getName() + ":" + glideElement);
}
}
hits.push("sys_id:" +sysid);
var parser = new global.JSON();
var parsed = parser.decode(hits);
gs.log(parsed,"soze");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 03:45 AM
Hi,
Do not use decode. It is a old fashion and sometimes not supported.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-27-2018 03:59 AM