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

My response is like this:

{
    "deskID":"148"
    "error":""
}

and I want to retrieve the desk ID, so tried this:

var responseBody1 = response1.getBody();
var jsonObject = JSON.parse(responseBody1);
gs.info('number='+jsonObject.deskID);

But with background script I am not getting any result?

Hi Dave,

 

Are you able to set u_vendor_ref_number?

 

if yes, can you share the steps?

 

 

 

Hi.  yes this what I am using at the end of my Business Rule:

var jsonBody = response.getBody();
var jsonObject = JSON.parse(jsonBody);
gs.log('Number=' + jsonObject.ticketId); // you'll need to check the jsonBody to see what jsonObject you need to use

current.setValue('u_vendor_ref_number', jsonObject.ticketId);

I tried the same, But not working for me and really not getting the reason. Below is the info that i could see in syslog

find_real_file.png

Below is my script

var jsonObject = JSON.parse(responseBody);
 gs.info('Summary='+jsonObject.fields.summary);
current.setValue('u_jira_sys_id',jsonObject.fields.summary);

 

below is the response i received from REST

 "fields": {
        "summary": testing please ignore,
        "resolution": null,

}

 

Any Suggesion?

 

Are you doing this in a BEFORE or AFTER business rule?

Not to be too picky, but your summary value in the JSON should be enclosed in double quotes (if you have the capability to do so.)