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

If u_jira_sys_id is a reference field, and jsonObject.summary contains "testing please ignore", you're going to have issues. The reference field expects a sys_id.

Under the assumption that it is a reference field AND there's a table somewhere that has a record with a display value "testing please ignore", then you can set the sys_id on the reference field, effectively "pointing" the reference field to the record with that display value using the setDisplayValue() method.

Ex:

var prbNumber = "PRB0001001";
// Update the problem this incident points to
current.problem.setDisplayValue(prbNumber);

If it's simply a string to hold a guid from another system, that's OK. Please clarify.

Its a string Field. and below is something i see in syslog

 

find_real_file.png

manish123
Giga Guru

Hi Chuck,



Thanks for your response. But here i would like to develop PUT method. And whenever any work notes change in either instance's incident, it will gets passed to other instance's incident.


Sounds pretty basic to me. Use the REST API Explorer to build and test your content. When you are ready to tie it to a business rule, click the ServiceNow link to view the code snippet and get started with the code.



Getting Started with REST - ServiceNow Wiki


REST API Explorer - ServiceNow Wiki


REST API  


manish123
Giga Guru

Hi Chuck,



As I was trying to push work notes update from one instance to another by clicking on Update button . Through this UI action, I am calling script action through event queue and below is the code:-



try {


var r = new sn_ws.RESTMessageV2('Test API', 'put');


gs.log('Called till here');


r.setRequestBody("{\"work_notes\":\"This is Test 2\"}");


var response = r.execute();


gs.log('Instance B Update ');


  }


catch(ex) {


var message = ex.getMessage();


}


The End point has been setup to the Instance A's API. Which i don't think i would need to define explicitly here. But its just printing the log message however not updating the linked incident in Instance B.



Could you please let me know what I am missing & what needs to correct?



Thanks in advance!!!