Contact Us

It is often the situation that you will need to work with many types of NetSuite item records without being given the specific type of item record beforehand. The following code blocks should provide an intuitive solution on how to process multiple types of item records.

About NetSuite Item Records and Types

NetSuite item records include a wide variety of types, each with a specific function. Whether dealing with inventory items, non-inventory parts, or service items in NetSuite, developers often face the challenge of programmatically accessing and manipulating the various item types using SuiteScript. Given the differences in data structures and functionalities across the different item types, it's crucial to understand how to dynamically load and work with them efficiently.

1. const ITEM_MAPPING

Somewhere in your function, initialize this object:

const ITEM_MAPPING = { "Assembly": record.Type.ASSEMBLY_ITEM, "Description": record.Type.DESCRIPTION_ITEM, "Discount": record.Type.DISCOUNT_ITEM, "GiftCert": record.Type.GIFT_CERTIFICATE_ITEM, "InvtPart": record.Type.INVENTORY_ITEM, "Group": record.Type.ITEM_GROUP, "Kit": record.Type.KIT_ITEM, "Markup": record.Type.MARKUP_ITEM, "NonInvtPart": record.Type.NON_INVENTORY_ITEM, "OthCharge": record.Type.OTHER_CHARGE_ITEM, "Payment": record.Type.PAYMENT_ITEM, "Service": record.Type.SERVICE_ITEM, "Subtotal": record.Type.SUBTOTAL_ITEM };

2. search.createColumn

In your search for fetching item records, include the record type as a column.

search.createColumn({name: "type", label: "Type"})

3. const itemRecord

When loading the item record, use the item mapping in square bracket notation to utilize the correct record.Type.

const itemRecord = record.load({ type: ITEM_MAPPING[result.getValue("type")], id: result.getValue("internalid") });

Conclusion

Effectively managing multiple item types in SuiteScript requires a thorough understanding of the differences between these types and the appropriate methods to handle them. By utilizing dynamic loading techniques and adhering to best practices, NetSuite developers can create robust scripts that seamlessly interact with any item record.

Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!

Oracle NetSuite Alliance Partner & Commerce Partner

If you have questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

Horizontal Anchor Group logo orange anchor icon navy Anchor Group text

Tagged with Training