Points To Be Noted While Passing a Boolean Variable To Backend In An Extension

While working on any SCA extension having both javascript and suite script module, if we are passing a boolean value(true/false) to the suite script module there is a chance for changing the variable type to string.

So if you are checking any condition with that variable make sure to check the type of the variable both in the backend and front end.

Here the boolean value is getting as a string in the backend so we are checking the value as a string whether ‘true’ or ‘false’.

This may happen while you are passing values using the service URL method.

Code snippet: Javascript module

var cartCheck = false;

 var serviceUrl= Utils.getAbsoluteUrl('services/WebTracking.Service.ss')
                    console.log("serviceUrl", serviceUrl);
                    jQuery.get(serviceUrl, {
                        data: uniqueID,
                        customerId: customerId,
                        cartCheck: cartCheck
                    }).then(function(res) {
                        console.log("res", res);
                        console.log("res.cartId", res.cartId);
                        cartID = res.cartId;
                        appendScript(cartID);
                        console.log("cartID inside then fn", cartID);
                    })

Code Snippet: Suite Script module

getData: function(data, customerId, cartCheck) {
            console.error("Inside model: data", data);
            console.error("Inside model: cartCheck", cartCheck);
            try {
                if (cartCheck == 'true') { // here using 'true' as string to check, beacuse the value is coming as string and possible values are 'true' or 'false' as strings.
                    custRecord.setFieldValue('custentity_cart_id', data);
                    nlapiSubmitRecord(custRecord);
                    console.error("IF ture cartId", cartId);
                } else {
                    var cartId = custRecord.getFieldValue('custentity_cart_id');
                    console.error("customer field cartId", cartId);
                }
            } catch (e) {
                console.error("Error in loading customer record", e);
            }
            return {
                cartId:cartId
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *