How to map a boolean type field in scripted REST API?

Devi12
Giga Guru

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!

6 REPLIES 6

Can you share the rest of your script?

Comment out the first 2 lines as I do not believe they are necessary.

I was able to successfully test the above code by removing the first two lines and sending a payload like this:

{"primary_contact":"True"}

Code looks like this:

(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;

    if (primaryTF == 'True')
        primaryBool = true;

    var body = {};
    body.primary = primaryBool;

    response.setBody(body);

})(request, response);

Can you test the above with REST API Explorer?