Creating an Inventory Detail Subrecord on a Body Field 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 could also add the subrecord using standard mode. For general details about using either approach to add a sublist subrecord, see Using SuiteScript 2.x to Create a Body Field Subrecord.

To learn about SuiteScript scripting modes, see SuiteScript 2.x Standard and Dynamic Modes

          require(['N/record'], function(record) {

       // Create a lot numbered assembly item.
       var 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'
       });
       var itemId = item.save();

       // Create the assembly build record.
       var 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.
       var 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.
       var recId = rec.save();
       log.debug({
              title: 'Record created successfully',
              details: 'Id: ' + recId
       });
}); 

        

Related Topics

Using SuiteScript 2.x to Create a Body Field Subrecord
Creating an Address on a Subsidiary Record Example

General Notices