How to map a boolean type field in scripted REST API?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2022 07:25 AM
Hi,
For Vendor data import I am doing integration using Scripted REST API. The requirement here is: The field "primary contact" is a boolean type (True/False check box), which is not maintained in third party. Third party is able to send Y/N only. For this How can I change my script to map "Y" with "True" and "N" with "False" in Scripted REST API. Is it possible to do the mapping or third party needs to do changes?
Thanks in advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2022 07:43 AM
Hi,
If you have created custom Scripted REST API then you can handle this through script.
If you are using OOB API's then you need to contact third part team and ask them to update the request body while making API call and do the mapping at their end.
Thanks,
Anil Lande
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2022 07:45 AM
Your Scripted REST API could look something like this:
var str = request.body.dataString;
var obj = JSON.parse(str);
var primaryBool = false;
var primaryTF = obj.primaryContact; //Or whatever the name of your request parameter would be
if (primaryTF == 'True')
primaryBool = true;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2022 08:09 AM
I tried this code, it is showing below error.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2022 08:11 AM
This is the declaration:
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var reqdata = request.body.data;
var parsedData = reqdata;
var str = request.body.dataString;
var obj = JSON.parse(str);
var primaryBool = false;
var primaryTF = obj.primary_contact;