I have Client Script running through scriptable ca...
# suitecommerce
l
I have Client Script running through scriptable cart, When I changed the address on SCA checkout page, log("here") is printing 6 time, this is so weird, Note that I do not have any customization on SCA and on NetSuite side only Client Script and Scriptable cart is turned ON.
Copy code
if(context.sublistId =='item' && context == 'WEBSTORE'){
log.debug("here");
}
s
Recursion is a common problem with scriptable cart. Without looking at your code, I can’t tell you if it should be happening, but a common workaround is to use a global variable to prevent it from happening. See https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/article_0151255693.html#subsect_69145908833
l
Below is the code, I'll customize later, However I want to avoid printing logs multiple times, One question Can I use global variables with fieldChanged as well? because in documentation they uses global variable for "customRecalc" fucntion only.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(['N/ui/dialog','N/currentRecord'], function(dialog,currentRecord1) {

function fieldChanged(context) {
    log.debug("fieldChanged");
}

  function sublistChanged(context) {
    log.debug("sublistChanged");
}
    return {
        fieldChanged: fieldChanged,
        sublistChanged: sublistChanged,
    };
});
s
Conceptually, using a variable to prevent recursion is not a novel concept. It’s used throughout all kinds of JavaScript applications, and in other programming languages
You just have to remember to reset it after you’re done
l
Make Sense, Thanks
e
@Lucas besides what Steve has explained to you, you are not checking the specific list or field you want to capture, there are some values that are updated whenever another is changed, so all the fields that are changing trigger the fieldChanged/sublistChanged, you need add the field id and it would be more accurate. For example when you want to check when a ship method has changed, then you validate if the trigger was caused by 'shipmethod' inside the fieldChanged method.
❤️ 1
l
Thanks much
1