0
votes

I am looking to integrate with NetSuite from an external quoting system. Everything works fine if I use standard Non-Inventory Items and I am able to create a Sales Order.

The problem that I run into is when I add a line that is an Item Group, it instantiates a new copy of all of the items that are part of that Item Group which do not have all the defaults needed to properly save.

I have tried to extract a SalesOrder that I had manually created in NetSuite with Item Groups, and then map that back to a new SalesOrder request, and that too also results in the same error.

I would like to be able to leverage item groups, curious to know if there is a way for this to work through the API, or will I need to write SuiteScript?

2

2 Answers

1
votes

TLDR; Yes, Item Groups work in server-side SuiteScript. They can be added just like normal items. The "instantiates a new copy of all of the items that are part of that Item Group" behavior you have described is by design.

The longer version:

For those who may stumble across this in 2021... I can confirm that I have been managing a successful integration with Netsuite using many Item Groups for over a year now. So, they can be created with server-side scripts!

However, we should clarify what you mean when you say "is there a way for this to work through the API". Netsuite allows you to write custom scripts called RESTlets that are basically a write-your-own API. Netsuite also has a SOAP API and a REST API interface that are built-in. My integration has been handled through a RESTlet written in SuiteScript and hosted by Netsuite.

You should also know that Item Groups in Netsuite are meant to be a shorthand for adding many items at once. So, the behavior you describe where you add the single line but then Netsuite explodes that one line into the member items of the group is how Item Groups are designed to work. As a result, it is more challenging to manage custom pricing or other options for Item Groups. There's almost no difference between adding an Item Group and just manually adding the member items one-at-a-time when it's all said and done. Instead, you may try using a Kit item, which allows you to set its own pricing, income account, class and other settings. You can check out this awesome article by Marty Zigman on the difference between Kits and Item Groups.

If Item Groups really is what you're looking for, and you want to add them to a Sales Order via SuiteScript, then you can add them just like any normal item. The tricky part is trying to modify values on the member item lines that are added dynamically by Netsuite. In that case, I recommend creating a Sales Order in dynamic mode, adding the item groups (Netsuite will auto-expand them in dynamic mode), and then looping back through the items to make necessary changes like so:

const so = record.create({ type: record.Type.SALES_ORDER, isDynamic: true })

/* Set other necessary values here (customer, date, etc.). Then... */

so.selectNewLine({ sublistId: "item" })
so.setCurrentSublistValue({ 
  sublistId: "item", 
  fieldId: "item", 
  value: "<internalId of Item Group>" 
})
so.commitLine({ sublistId: "item" })

/* The Item Group will have expanded at this point */

const lineCount = so.getLineCount({ sublistId: "item" })
for(var lineNum = 0; lineNum < lineCount; lineNum++) {
  so.selectLine({sublistId: "item", line: lineNum})
  // Make whatever changes to the line. For example: change the price...
  if(/*check if this is the correct item...*/) {
    so.setCurrentSublistValue({sublistId: "item", fieldId: "price", value: -1}) // Custom price
    so.setCurrentSublistValue({sublistId: "item", fieldId: "rate", value: 200}) // $200
    so.commitLine({sublistId: "item"})
  }
}

const salesOrderId = so.save()

Please remember that Item Groups might have a header/footer line in addition to the lines for the member items. This will be the case if you have checked the REFERENCE START/END LINES ON PICKING TICKETS option when creating the Item Group.

0
votes

So, an 'Item Group' is really nothing more than a pre-baked "Client-Side only" script. It simply stores the ids of the items in the group .. then when you choose it, it populates the lines (in the browser) with those item ids.

Because of this, Item Groups cannot be used server-side. So, you can't use them in scripts or integration.