How to define optional paramters on POST method content?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 12:40 AM
Hello Community,
I've a requirement to avoid sending empty parameters without forming the request body on any script. Is there a way we can handle this on the content of the POST method of a REST message?
Scenario: There are certain variables on the catalog form which are not mandatory. So if the user does not provide any input to those variables, it should not send any query parameters for those empty values. I've to handle it on the content of the POST method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 06:28 AM - edited 06-13-2024 06:34 AM
It's not possible via that approach. Instead you have to build the request body via script and then set the result to the REST Message object manually.
Approach (not the final solution!)
var _objRestMessage = new sn_ws.RESTMessageV2("<NAME OF REST Message record");
var _objRequestBody = {};
var _strRequestedBy = '';
if (_strRequestedBy != '') {
_objRequestBody.requested_by = _strRequestedBy;
}
_objRestMessage.setRequestBody(JSON.stringify(_objRequestBody, null, 4));