How to get response data from REST ? #8529631
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2018 03:37 AM
Get data from Rest payload......ssecorp##
var r = new sn_ws.RESTMessageV2('x Integration', 'Default GET');
r.setStringParameterNoEscape('ci', 'y');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parser = new JSONParser();
var parsedData = parser.parse(responseBody);
var stat=parsedData[0]["parameter1"].parameter1A;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-17-2018 01:49 PM
Looks like you've got it.
I would recommend you skip `JSONParser` and use the newer JSON.parse()
var r = new sn_ws.RESTMessageV2('x Integration', 'Default GET');
r.setStringParameterNoEscape('ci', 'y');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
var parsed = JSON.parse(responseBody);
// Read/loop/handle object as needed below...
var stat=parsed[0]["parameter1"].parameter1A;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 06:13 AM
for (var i = 0; i < 100000 ;i+=5000) {
var request = new sn_ws.RESTMessageV2();
request.setEndpoint('https://x.service-now.com/api/now/table/incident?sysparm_limit=5000&sysparm_offset=' + parseInt(i).toFixed(0));
request.setHttpMethod('GET');
//Eg. UserName="admin", Password="admin" for this code sample.
var user = 'hello';
var password = 'world';
request.setBasicAuth(user,password);
request.setRequestHeader("Accept","application/json");
var response = request.execute();
parseresponse(response);
}
function parseresponse(rep){
var parsing=JSON.parse(rep.getBody());
var fact=parsing.result;
for (var i=0; i < fact.length; i++) {
//gs.print(global.JSON.stringify(fact[i]));
insertrecords(fact[i]);
}
}
//gs.addInfoMessage(response.getBody());
function insertrecords(body){
var gr = new GlideRecord('incident');
for (var key in body) {
if (body.hasOwnProperty(key)) {
gr[key] = body[key];
}
}
gr.setWorkflow(false);
var id = gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2018 06:47 AM
Hi Venakula,
So you want to parse the json response and get value. Can you share the json response so that I can help in parsing the json.
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-26-2018 01:37 AM