Creating a Landed Cost Sublist Subrecord Example

The following example creates a vendor bill record. This example creates one line in the item sublist. It also sets the Landed Cost per Line option to true. With this configuration, it is possible to create a landed cost subrecord for each line.

To use this example, the Landed Cost feature must be enabled at Setup > Company > Enable Features , on the Items & Inventory subtab.

This example uses standard mode, but you could also add the subrecord using dynamic mode. For general details about using either approach to add a sublist subrecord, see Using SuiteScript 2.x to Create a Subrecord in a Sublist Field.

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

          /**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */

define([ 'N/record' ],function(record) {
    function afterSubmit(context) {
        // Create the record.
        var rec = record.create({
            type : record.Type.VENDOR_BILL,
            isDynamic: false
        });

        // Set body fields on the record.
        rec.setValue({
            fieldId: 'entity',
            value: '1663'
        });

        rec.setValue({
            fieldId: 'location',
            value: '6'
        });
 
        rec.setValue({
            fieldId: 'tranid',
            value: '101A'
        });

        // Set the Landed Cost per Line field to true.
        rec.setValue({
            fieldId: 'landedcostperline',
            value: true
        });

        // Add an item to the Item sublist.
        rec.insertLine({
            sublistId: 'item',
            line: 0
        });

        // Set values on the sublist line.
        rec.setSublistValue({
            sublistId: 'item',
            fieldId: 'item',
            line: 0,
            value: '599'
        });

        rec.setSublistValue({
            sublistId: 'item',
            fieldId: 'quantity',
            line: 0,
            value: 1
        });

        rec.setSublistValue({
            sublistId: 'item',
            fieldId: 'location',
            line: 0,
            value: '6'
        });

        // Create the subrecord.
        var subrec = rec.getSublistSubrecord({
            sublistId: 'item',
            fieldId: 'landedcost',
            line: 0
        });

        // Add a line to the subrecord's Landed Cost Data sublist.
        subrec.insertLine({
            sublistId: 'landedcostdata',
            line: 0
        });

        // Set values on the subrecord's sublist line.
        subrec.setSublistValue({
            sublistId: 'landedcostdata',
            fieldId: 'costcategory',
            line: 0,
            value: 2
        });

        subrec.setSublistValue({
            sublistId: 'landedcostdata',
            fieldId: 'amount',
            line: 0,
            value: 17.85
        });

        // Save the record.
        try {
            var recId = rec.save();
            log.debug({
                title: 'Record created successfully',
                details: 'Id: ' + recId
            });
        } catch (e) {
            log.error({
                title: e.name,
                details: e.message
              });
        }
    }
    return {
        afterSubmit: afterSubmit
    };
}); 

        

Related Topics

Using SuiteScript 2.x to Create a Subrecord in a Sublist Field
Creating an Inventory Detail Sublist Subrecord Example
Creating an Address Sublist Subrecord Example
Creating an Order Schedule Sublist Subrecord Example

General Notices