netsuitesuitescriptsuitescript2.0clientscript

Netsuite - Suitescript 2.X: Inbound shipment "items" sublist update


I need to update a sublist ('items') field ('receivinglocation') on inbound shipment entry. When i create an inbound shipment from user interface, i need to update all item line locations from a body field ('customlocation'). I've tried to do that throught a Clientscript:

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(['N/currentRecord'],
/**
 * @param{currentRecord} currentRecord
 */
function(currentRecord) {
    
    /**
     * Validation function to be executed when record is saved.
     *
     * @param {Object} scriptContext
     * @param {Record} scriptContext.currentRecord - Current form record
     * @returns {boolean} Return true if record is valid
     *
     * @since 2015.2
     */
    function saveRecord(scriptContext) {

        try {
            var lines = scriptContext.currentRecord.getLineCount({sublistId: 'items'});
            var mainLocationValue = scriptContext.currentRecord.getValue({
                fieldId: 'customlocation'
            });
            if (mainLocationValue != '' && mainLocationValue != null) {
                for (var i=0; i<lines; i++){
                    scriptContext.currentRecord.selectLine({sublistId: 'items',line: i});
                    scriptContext.currentRecord.setCurrentSublistValue({sublistId: 'items',fieldId: 'receivinglocation',value: mainLocationValue,ignoreFieldChange: true});
                    scriptContext.currentRecord.commitLine({sublistId: 'items'});
                }
            }
        }
        catch (e) {
                    log.debug({
                        title: 'Error Details',
                        details: e
                    })
        }
    }

    return {
        saveRecord: saveRecord
    };
    
});

But the error is always the same from the validation form: "FAILED_FORM_VALIDATION" - "Form validation failed. You cannot submit this record"


Solution

  • Not sure if this is where your error is coming from, but you do have to return true from the saveRecord() function to allow NetSuite to save the record. You can see a note to this effect directly in the JSDoc section of the script you posted:

    @returns {boolean} Return true if record is valid