Creating an Inventory Detail Body Field Subrecord Example

The following example shows how to create an assembly build record that includes an inventory detail subrecord. In this case, the subrecord is contained in a body field called inventory detail.

To use this example, you must meet the following prerequisites:

This example uses dynamic mode, but you can also use standard mode to add the subrecord. For general details about using either approach to add a body field subrecord, see Creating a Body Field Subrecord in SuiteScript 2.1.

To learn about SuiteScript scripting modes, see SuiteScript 2.1 Standard and Dynamic Record Modes

          /**
 * @NApiVersion 2.1
 */
require(['N/record'], (record) => {

       // Create a lot numbered assembly item.
       const item = record.create({
              type: record.Type.LOT_NUMBERED_ASSEMBLY_ITEM,
              isDynamic: true
       });
       item.setValue({
              fieldId: 'itemid',
              value: 'lot numbered item'
       });
       item.setValue({
              fieldId: 'taxschedule',
              value: 2
       });
       item.selectNewLine({
              sublistId: 'member'
       });
       item.setCurrentSublistValue({
              sublistId: 'member',
              fieldId: 'item',
              value: 233
       });
       item.commitLine({
              sublistId: 'member'
       });
       const itemId = item.save();

       // Create the assembly build record.
       const rec = record.create({
              type: record.Type.ASSEMBLY_BUILD,
              isDynamic: true
       });

       // Set body fields.
       rec.setValue({
              fieldId: 'subsidiary',
              value: '1'
       });
       rec.setValue({
              fieldId: 'location',
              value: '1'
       });
       rec.setValue({
              fieldId: 'item',
              value: itemId
       });
       rec.setValue({
              fieldId: 'quantity',
              value: 1
       });

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

       // Create a line on the subrecord's inventory assignment sublist.
       subrec.selectNewLine({
              sublistId: 'inventoryassignment',
       });
       subrec.setCurrentSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'receiptinventorynumber',
              value: '012345'
       });
       subrec.setCurrentSublistValue({
              sublistId: 'inventoryassignment',
              fieldId: 'quantity',
              value: 1
       });
       subrec.commitLine({
              sublistId: 'inventoryassignment'
       });

       // Save the record.
       const recId = rec.save();
       log.debug({
              title: 'Record created successfully',
              details: 'Id: ' + recId
       });
}); 

        

Related Topics

General Notices