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

How to print the request Body in SOAP Message?

suman12
Tera Contributor

Hi all,

 

Building the SOAP outbound in scoped application, Please guide me to put log the requestBody before hitting the endpoint.

Using the below code geeting null value

 var s = new sn_ws.SOAPMessageV2('Some string','somestring');

 var requestBody = s.getRequestBody();

  gs.info('requestBody ' + requestBody);

output: getting null instead of body

 

Thanks

6 REPLIES 6

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Suman,

There's a following note in the ServiceNow documentation.

Before calling the getRequestBody() method, you must call the execute() method to obtain the response object.

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/sn_ws-namespace/c_SOAPMessag...

Beside Akshay's reply in executing s.execute(), the getRequestBody() should be done on the response of the .execute() instead of on sn_ws._SOAPMessageV2().

So the complete code is as follows.

var s = new sn_ws.SOAPMessageV2('Some string','somestring');
var response = s.execute();    // insert this line
var requestBody = response.getRequestBody();  // change to use "response" instead of "s"
gs.info('requestBody ' + requestBody);

Hi Hitoshi,

 

Thanks for the reply. It working now.