Boolean data type issue in inbound rest API

Mohan Mallapu
Kilo Sage

Hi All,

I have one inbound rest  Get API call to get the user details from sys_user table. While testing this from postman below are the response fields we configured and getting as a response.  but here the active status field( Boolean data type) was resulting as a string.

Result from postman:

{

            "active": "false",

            "email": ""

        },

Expecting results: Without any quotations , how we could do achieve this..

 

{

            "active": false,

            "email": ""

        },



Much appreciated for the response...

1 REPLY 1

Amit Gujarathi
Giga Sage
Giga Sage

HI @Mohan Mallapu ,
I trust you are doing great.

  1. Navigate to the ServiceNow instance and open the relevant API script or Business Rule that handles the Get API call for retrieving user details from the sys_user table.

  2. Locate the section of the script where the API response is being constructed or modified.

  3. Identify the part where the "active" field is being assigned a value. It might look something like this:

 

var active = gs.getProperty("glide.ui.escape_all_script");

 

  • To convert the "active" field value to a boolean, you can use the JavaScript Boolean() function. Modify the code to resemble the following:

 

var active = Boolean(gs.getProperty("glide.ui.escape_all_script"));

 

  • By using the Boolean() function, the string value will be converted to a boolean. This will remove the quotation marks from the "active" field and return it as a proper boolean value.

    1. Save the changes to the script or Business Rule.

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi