BOM

A Bill of Materials, or BOM, lists the quantities of raw materials, assemblies, sub-components, and parts needed to manufacture a product. A BOM can be used to communicate between manufacturing partners, multiple facilities within the organization, or with a single manufacturing plant. The BOM that is scriptable in NetSuite is the Advanced BOM.

This record is supported when the Advanced BOM feature is enabled at Setup > Company > Enable Features, on the Items & Inventory tab. After this feature has been enabled, the Advanced BOM replaces the Assembly/Bill of Materials record.

For help working with this record in the UI, see Advanced Bill of Materials.

In the UI, this record is accessed by going to Lists > Supply Chain > Bill of Materials.

The internal ID for this record is bom.

See the SuiteScript Records Browser for all internal IDs associated with this record.

Note:

For information about using the SuiteScript Records Browser, see Working with the SuiteScript Records Browser in the NetSuite Help Center.

For information about scripting with this record in SuiteScript, see the following help topics:

Supported Script Types

The BOM record is scriptable in client and server SuiteScript.

Supported Functions

The BOM record is fully scriptable, which means that it can be read, created, edited, copied, deleted, and searched using SuiteScript.

BOM Code Samples

Create a BOM

The following sample shows how to create a new bill of materials record.

          require(['N/record'], function(record){
      function createBom(values){
        var rec = record.create({
            type: record.Type.BOM,
            isDynamic: true
        });
        for (var key in values){
            if (values.hasOwnProperty(key)){
                rec.setValue({
                    fieldId: key,
                    value: values[key]
                });
            }
        }
        return rec.save({enableSourcing: false, ignoreMandatoryFields: false});
    }
    var bomId = createBom({
        'name': 'SS 2.0 BoM',
        'subsidiary': [4,5],
        'includechildren' : true,
        'usecomponentyield': true
    });
}); 

        

Copy a BOM

The following sample shows how to copy a bill of materials record.

          require(['N/record'],function(record){
    function copyBom(bomId, values){
        var rec = record.copy({
            type: record.Type.BOM,
            id: bomId,
            isDynamic: true
        });
        for (var key in values){
            if (values.hasOwnProperty(key)){
                rec.setValue({
                    fieldId: key,
                    value: values[key]
                });
            }
        }
        return rec.save({enableSourcing: false, ignoreMandatoryFields: false});
    }
    var bomId = copyBom(1,{
        'name': 'SS 2.0 BoM Copy',
        'subsidiary': [4],
        'includechildren' : false,
        'usecomponentyield': false
    });
}); 

        

Delete a BOM

The following sample shows how to delete a bill of materials record.

          require(['N/record'],function(record){
    function deleteBom(bomId){
        record.delete({
            type: record.Type.BOM,
            id: bomId
        });
    }
    deleteBom(2);
}); 

        

Full BOM Code Sample

The following sample shows how to create, copy, and delete a bill of materials record, including edits to BOM revisions. For samples specific to BOM revisions, see BOM Revision Code Samples.

          require(['N/record', 'N/search'], function(record, search){
    // create bill of materials (function)
    function createBom(values){
        var rec = record.create({
            type: 'bom',
            isDynamic: true
        });
        for (var key in values){
            if (values.hasOwnProperty(key)){
                rec.setValue({
                    fieldId: key,
                    value: values[key]
                });
            }
        }
        return rec.save({
            enableSourcing: false,
            ignoreMandatoryFields: false
        });
    }

    // create bill of materials revision (function)
    function createBomRevision(values, components){
        var rec = record.create({
            type: 'bomrevision',
            isDynamic: true
        });
        for (var key in values){
            if (values.hasOwnProperty(key)){
                rec.setValue({
                    fieldId: key,
                    value: values[key]
                });
            }
        }
        for (var i in components){
            rec.selectNewLine({
                sublistId: 'component'
            });
            for (var key in components[i]){
                if (components[i].hasOwnProperty(key)){
                    rec.setCurrentSublistValue({
                        sublistId: 'component',
                        fieldId: key,
                        value: components[i][key]
                    });
                }
            }
            rec.commitLine({sublistId: 'component'});
        }
        return rec.save({enableSourcing: false, ignoreMandatoryFields: false});
    }

    // update bill of materials revision (function)
    function updateBomRevision(revisionId, values){
        var rec = record.load({
            type: 'bomrevision',
            id: revisionId,
            isDynamic: true
        });
        for (var key in values){
            if (values.hasOwnProperty(key)){
                rec.setValue({
                    fieldId: key,
                    value: values[key]
                });
            }
        }
        return rec.save({enableSourcing: false, ignoreMandatoryFields: false});
    }

    // copy bill of materials (function)
    function copyBom(bomId, values){
        var rec = record.copy({
            type: 'bom',
            id: bomId
        });
        for (var key in values){
            if (values.hasOwnProperty(key)){
                rec.setValue({
                    fieldId: key,
                    value: values[key]
                });
            }
        }
        return rec.save({enableSourcing: false, ignoreMandatoryFields: false});
    }

    // delete bill of materials (function)
    function deleteBom(bomId){
        record.delete({
            type: 'bom',
            id: bomId
        });
    }

    // get bill of materials revisions (function)
    function getBomRevisions(bomId){
        //search ids for all revisions for given BoM
        var searchObj = search.create({
            type: 'bomrevision',
            filters: [
                ['billofmaterials', 'is', [bomId]]
            ],
            columns: ['name']
        });
        var revisions = [];
        searchObj.run().each(function(result){
            revisions.push({
                'id': result.id,
                'name': result.getValue('name')
            });
            return true;
        });
        return revisions;
    }

    // create BoM - call createBom function
    var bom1Id = createBom({
        'name': 'SS 2.0 BoM',
        'subsidiary': [4,5],
        'includechildren': true,
        'usecomponentyield': true
    });

       // create new BoM revision - call createBomRevision function
    var bom1Rev1Id = createBomRevision({
        'billofmaterials': bom1Id,
        'name': 'Rev.1',
        'effectivestartdate': new Date('1/1/2017')
           }, [
            {'item': 63, 'bomquantity': 1},
            {'item': 64, 'bomquantity': 2}
    ]);

    // update BoM Revision Effective End Date to prevent a collision - call updateBomRevision function
    bom1Rev1Id = updateBomRevision(bom1Rev1Id, {
        'effectiveenddate': new Date('12/31/2018')
    });

      // create another new BoM revision - call createBomRevision function
    var bom1Rev2Id = createBomRevision({
        'billofmaterials': bom1Id,
        'name': 'Rev.2',
        'effectivestartdate': new Date('1/1/2019')
        }, [
            {'item': 64, 'bomquantity': 3},
            {'item': 62, 'bomquantity': 1}
    ]);

      // copy BoM and update some values - call copyBom function */
    var bom2Id = copyBom(bom1Id, {
        'name': 'SS 2.0 BoM Copy',
        'subsidiary': [4],
        'usecomponentyield': false,
        'includechildren': false
    });

      // find BoM Revisions of BoM - call getBomRevisions function
    var revisions = getBomRevisions(bom1Id);
    // update first component's Component Yield value of each found BoM Revision
    for (var i = 0; i < revisions.length; i++){
        rec = record.load({
            type: 'bomrevision',
            id: revisions[i].id
        });
        rec.setSublistValue({
            sublistId: 'component',
            fieldId: 'componentyield',
            line: 0,
            value: 50
        });
        rec.save();
    }

    // delete BoMs - call deleteBom function
    deleteBom(bom1Id);
    deleteBom(bom2Id);
}); 

        

Related Topics

Advanced Bill of Materials
Working with the SuiteScript Records Browser
SuiteCloud Supported Records
Lists

General Notices