Search code examples
suitescript

Suitescript 2.0 - log.debug repeating value lines


I'm working on a client script, but when I do a simple getValue() on the customer field and log.debug, I get repeating output lines and I'm not sure why. Is this normal?

Output

This my fieldChanged code:

function fieldChanged(context) {
    var newRec = context.currentRecord;
    if(newRec.fieldId = 'entity') {

        var custId = newRec.getValue ({
            fieldId: 'entity'
        });

        log.debug({
            title: 'id: ' + custId
        });

    }
}

Solution

  • Change the line below:

    if(newRec.fieldId = 'entity') 
    

    To something like

    if(context.fieldId === 'entity') 
    

    You're getting repeating output lines because whenever a field is changed, you're not doing a check on the current fieldId in the context object instead checking the context.currentRecord.fieldId which I'm not sure what evaluates to.

    Check this out for more info: fieldChanged(scriptContext)