difference between request.body.data and request.body.dataString, Please explain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 05:07 AM
Hello,
what is the difference between request.body.data and request.body.dataString in scripted rest api's and which one is best because both are used for retrieving the request body, can anyone explain me with a good example please
Thnks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 05:28 AM
Hello,
It depends on the request that you are going to handle with the API and what you want to do with the data of the request.
If the format of the body is not JSON or XML, for example, it's recommended to use dataStream to handle the body in order to avoid a response error.
If you want to take the content and directly use the request as a string, you can use dataString (e.g. setting the content in a single Request Body field on a staging table).
Or if you need the body and the elements in the body, you can use the data object and take the details from the body.
Regards!
Kristian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 06:35 AM
We have asked our third party to send the request body in the JSON format and in this case it makes more sense to use below?
var reqData = request.body.data;
var caller=reqData.caller;
var summary= reqData.summary;
and so on rgt?
correct me if i am wrong.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2021 06:59 AM
Hello,
Yes, this way is perfectly fine. It's always a good practice if you add some additional checks to verify that the data you are receiving is valid and not empty.
You can check the entries separately, and you can also verify the body itself.
A common example for the body used in ServiceNow is the following one:
// If there's no payload and no query parameter we can return an error.
if (JSUtil.isEmpty(request.body.data)){
return new sn_ws_err.BadRequestError("Empty Body provided!");
}
Regards!
Kristian