ANS-1561 · SUITESCRIPT DEVELOPMENT

How to Resolve ‘Invalid Reference Key for Entity’ in Scripted Journal Entries?

Correct 'invalid reference key for entity' errors in NetSuite SuiteScript by ensuring proper record sourcing for journal entries.

Short answer

To resolve 'invalid reference key for entity' errors in scripted journal entries, ensure the record is created in dynamic mode to apply necessary sourcing when setting the subsidiary. Additionally, enable sourcing during the record submission process. This ensures all related fields, including the entity, are correctly recognized and populated, preventing validation failures.

Scenario

Users may encounter an 'invalid reference key for entity' error when attempting to create or submit journal entries via SuiteScript. This issue typically arises when the system fails to properly recognize or source the entity associated with the journal entry, often after the subsidiary has been set. The error indicates that a required reference key for the entity is missing or incorrectly linked.

Solution

The 'invalid reference key for entity' error in scripted journal entries often indicates that necessary sourcing is not being triggered when the subsidiary is set, or during record submission. To resolve this, ensure the following practices are implemented in your SuiteScript:

  1. Create the journal entry record in dynamic mode. This ensures that necessary sourcing is applied automatically when the subsidiary is set, allowing related fields like the entity to be correctly recognized.

javascript
record.create({type: 'journalentry', isDynamic: true})
  1. Enable sourcing when submitting the record. This explicitly triggers sourcing rules during the save operation, further ensuring that all referenced entities and other related data are properly validated and linked.

javascript
record.save({record: yourRecordObject, enableSourcing: true})

Implementing these steps helps ensure that all required entity references are correctly established and recognized within the journal entry.

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant