How to print the request Body in SOAP Message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 08:41 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 04:54 PM
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.
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 09:55 PM
Hi Hitoshi,
Thanks for the reply. It working now.