Search code examples
javascriptnetsuite

Updating Item Record Sublist values via Workflow Action Script


I am attempting to set defaults for the sales team. I have multi-location inventory activated and would like to default the Reorder Points via a Workflow Action Script. The Workflow is successfully setting values for a few other fields already.

 /**
 * @NApiVersion 2.x
 * @NScriptType WorkflowActionScript
 */
define([], function() {
    function onAction(scriptContext){
        log.debug({
            title: 'Start Script'
        });
      var objRecord = scriptContext.newRecord;
            objRecord.setCurrentSublistValue({
    sublistId: 'locations',
    fieldId: 'reorderpoint',
    line: 3,
    value: 0
    });
    }
    return {
        onAction: onAction
    }
}); 

I'm very new to this and have tried several different trigger points. When I set it to trigger on save, I receive: You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.

Any help is appreciated.

Not 100% on the field IDs but found another script referencing those.


Solution

  • There are a few issues with your script:

    1. Your method doesn't exist. You can't add setCurrentSublistValue with a line number. You need to select it first and then setCurrentSublistValue So here is the way:
    var lineNum = objRecord.selectLine({
        sublistId: 'item',
        line: 3
    });
    
    objRecord.setCurrentSublistValue({
        sublistId: 'item',
        fieldId: 'item',
        value: 123,
        ignoreFieldChange: true
    });
    
    
    1. You are selecting line 3, but are you sure that there are 4 lines? (Starting from 0)
    2. A loop with conditions should be better

    See https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_4273171484.html