Updating a Body Field Inventory Detail Subrecord Example

The following example loads an assembly build record. It also loads the subrecord in the Inventory Detail field and saves a change to it.

To use this example, make sure you meet these requirements:

For general details on updating body field subrecords, see Updating a Body Field Subrecord in SuiteScript 2.1.

          /**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */

define([ 'N/record' ], (record) => {
    const afterSubmit = (context) => {
        // Load the record.
        const rec = record.load({
            type: record.Type.ASSEMBLY_BUILD,
            id: 4918,
            isDynamic: true
        });

        // Load the subrecord.
         
        const subrec = rec.getSubrecord({
            fieldId: 'inventorydetail'
        });

        // Identify a line on the subrecord's sublist.
            
        subrec.selectLine({
            sublistId: 'inventoryassignment',
            line: 0
        });

        // Make changes to one sublist field.
            
        subrec.setCurrentSublistValue({
            sublistId: 'inventoryassignment',
            fieldId: 'receiptinventorynumber',
            value: '890123'
        });

        subrec.commitLine({
            sublistId: 'inventoryassignment'
        });
 
        // Save the record.
        try {
            const recId = rec.save();

            log.debug({
                title: 'Record updated successfully',
                details: 'Id: ' + recId
            });

            } catch (e) {
                log.error({
                title: e.name,
                details: e.message
            });
        }
    };
    return { afterSubmit };
}); 

        

Related Topics

General Notices