scripted REST - response body without "result"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 05:23 AM
Hi,
I created "scripted REST (Inbound POST) " and I need to set the response body to:
{ "ok": true, "stuff": "This is good" }
I used this code to "translate" JSON to JavaScript object because only javascript object is allowed as response body in ServiceNow scripted REST :
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 05:46 AM
Hi @RadovanK ,
Try this code instead, where you are setting the response body;
var responseBody = JSON.stringify({
"ok": true,
"stuff": "This is good"
});
response.getStreamWriter().writeString(responseBody);
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 05:52 AM
Hi @RadovanK
If you use response.getStreamWriter().writeString() function, it won't add addition "result" wrapper in your response body.
Thanks
Hope this helps.
If it helped please mark it as helpful.