The CreatorCon Call for Content is officially open! Get started here.

Retrieve value from Response.getBody() in JSON

manish123
Giga Guru

Hi All,

In REST integration, we are getting Response.getBody() with lots of fields and values respective to it. However, i would like to get some specific value from that Response.Could anyone please let me know how to get that? I tried with decode and Parse but still in log its displaying undefined.

1 ACCEPTED SOLUTION

Result does not appear to be an array. I'm reaching this as:



gs.log('Number=' + jsonObject.result.number);


View solution in original post

42 REPLIES 42

manish123
Giga Guru

I mean to ask whether do i need to do some change in HTTP Request to include anything special for Attachment. Currently, I have setup Accept & Content-Type and values are set to application/json. Or do i need to add anything on script include where I have written my POST and GET script?


manish123
Giga Guru

Hi Chuck,



Thanks for your reply.



I am calling a attachment script include function through UI action, which is responsible for creation of new ticket in instance B however now its creating duplicate incident row but it hasn't attached anything to it. However, when I update the ticket in instance A, changes will be carried forward to instance B as well as it passed the attached file to secondly created incident in instance B. That means that calling the same method on Update is working fine but during creation its create new duplicate row without any attachment.


For attachment I am passing end point of import staging table and then wriiten script push it to destination on update.



Any clue why it's not getting attached during creation or why duplicate incident created?


gilbertjimbob
Tera Contributor

Hi Chuck,

Sorry for posting this to an old thread but hopefully you (or someone) can help me (this is also my first post so be gentle).

We have created an integration between two instances for the first time using a REST connection and have managed to get it working okay so that when a record is created in instance A, a record is also created in instance B. We would like to record the number of the record created in instance B on the original record created in instance A, the response from the REST connection is providing this data but we are unable to extract it from the response body, can anyone help with this?

Here is an example of the response body:

{"import_set":"ISET1111111","staging_table":"u_test","result":[{"transform_map":"my test map","table":"incident","display_name":"number","display_value":"INC0111111","record_link":"https://myinstance.service-now.com/api/now/table/incident/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","status":"inserted","sys_id":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}]}

Here is the code we are using to get the response body:

var r = new sn_ws.RESTMessageV2('REST Message name', 'post');
var response = r.execute();
var responseBody = response.getBody();
var json = responseBody;
var obj = JSON.parse(json);

obj.staging_table returns 'u_test' as expected but obj.result.display_value returns undefined (even though the REST API docs say this should return the value of 'display_value') as does any of the 'items' in the 'result' field.

Any help would be much appreciated.