Adding a new Item using SuiteScript 2.0

I had this problem where I was attempting to add a new Noninventory for Resale item. The code ran without errors, but the item never showed up. That’s where it got weird.

Code that doesn’t work and doesn’t throw errors is a pain. After beating my head against the wall for more than an hour, I contacted NetSuite support. They gave me great insight into finding the problem. Nonetheless, this really needs to be on their enhancement list. Here is the workaround. Oh… and here is the elusive working example in SuiteScript 2.0 that successfully adds an item.

First, the workaround. On the statement that saves the item, single step into it.

Single Step into Save

It throws an error, which is actually caught and overlooked. In that error in Dev Tools, read the error message (e.message). That error, which is never reported is the key to your issue. It will say something like:

  1. Income account it missing
  2. Expense account is missing
  3. Tax Schedule is missing

Any required field (which is partially controllable by your NetSuite Admins) may show up in this list. If any of them is missing, no error and no new item!

Here is my working example. This example, combined with the debugging technique I gave you above might save you lots of frustration and wasted time.

()h… one more thing. I’ve also included an example of how to set base price on an item. This was also a little tricky.

        require([‘N/record’],
            function (record) {
                var newItem = record.create({
                    type: record.Type.NON_INVENTORY_ITEM,
                    isDynamic: true,
                });
                newItem.setValue({
                    fieldId: ‘itemid’,
                    value: item_name
                });
                newItem.setValue({
                    fieldId: ‘manufacturer’,
                    value: vendor_name
                });
                newItem.setValue({
                    fieldId: ‘salesdescription’,
                    value: description
                });
                newItem.setValue({
                    fieldId: ‘cost’,
                    value: cost
                });
                newItem.setValue({
                    fieldId: ‘incomeaccount’,
                    value: [your integer value here]
                })
                newItem.setValue({
                    fieldId: ‘expenseaccount’,
                    value: [your integer value here]
                })
                newItem.setValue({
                    fieldId: ‘taxschedule’,
                    value: 1
                })
                newItem.setValue({
                    fieldId: ‘pricinggroup’,
                    value: 1
                })
                newItem.selectLine({
                    sublistId: ‘price1’,
                    line: 0
                });
                newItem.setCurrentSublistValue({
                    sublistId: ‘price1’,
                    fieldId: ‘price_1_’,
                    value: listprice
                })
                newItem.commitLine({
                    sublistId: ‘price1’
                })
                var newItemResponse = newItem.save();
                console.log(newItemResponse);
                callback();
            }
        )

Purchasing Tab

SalePricing Tab

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s