GetValue Inexplicably Empty (NetSuite SuiteScript)

in , , September 24th, 2024
turned on laptop computer

Sometimes, when using SuiteScript to try to get a value from a NetSuite record object, the value is empty even though you know that the record has a value in that field. This specifically occurs when you are getting your record object through the event context.

const salesOrder = context.newRecord;
const entity = salesOrder.getValue('entity');
log.debug("entity", entity) //this is blank!

What is causing my GetValue to be empty?

The issue is probably occurring because your script is being triggered by an inline edit or ‘Xedit’ event.

Normally, the context.newRecord object contains the entire record; in cases where the triggering event is an inline edit, only an abridged version of the record is served via the script context. It contains some metadata about the record and the specific field(s) that were changed, but not every field.

In this example case, the ‘entity’ field was not the modified field, and so was not provided.

Solution and Code Sample

The easiest way to get around this, if you know that your script might be triggered by an inline event, is to load the record normally using the data provided in the context.newRecord object.

const salesOrder = record.load({
  type: context.newRecord.type,
  id: context.newRecord.id
})
const entity = salesOrder.getValue('entity');
log.debug("entity", entity) //this has a value now!

As a bonus, you may notice that this method doesn’t require you to know what the record type is to do this, so you can have a script be deployed to several different record types, and this will still work.

Author: JP Terneus


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 general questions about SuiteCommerce or more specific 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!

 
 

Want to keep learning?

Our team of NetSuite professionals has written articles on a wide variety of NetSuite topics, from SuiteCommerce tips, to recommended NetSuite solutions, to available support services, and more! 

Your cart