ANS-1699 · SUITESCRIPT DEVELOPMENT
How to Add Expense Lines Reliably in NetSuite Client-Side Scripts
Prevent data sourcing and tax calculation issues when adding expense lines via client-side scripts by ensuring synchronous execution for field value updates.
Short answer
To reliably add expense lines in NetSuite client scripts, use the `currentRecord.setCurrentSublistValue` function with the `fireSlavingSync` option set to `true`. This ensures that the script waits for all field sourcing and calculations, such as those related to Tax Nexus, to complete before proceeding, preventing data inconsistencies and save failures.
Scenario
When programmatically adding expense lines in NetSuite client-side scripts, users may encounter issues such as lines failing to save or inconsistent data. This often stems from the script not properly waiting for all dependent field sourcing and calculations, especially those related to Tax Nexus configurations, to complete before proceeding.
Solution
When encountering issues with line item manipulation in client-side SuiteScripts, it is recommended to utilize synchronous mode when setting line fields. This ensures predictable script execution by forcing the script to wait for any specified sourcing to complete before continuing.The SuiteScript 2.x function currentRecord.setCurrentSublistValue includes an option for synchronous execution:
currentRecord.setCurrentSublistValue(options)The fireSlavingSync option within this function is relevant for client SuiteScripts. In server scripts (such as user event scripts), this option will always execute as true. In client scripts, if the fireSlavingSync option is not explicitly set, its default value is false, and the API executes asynchronously. If set to true, this API executes synchronously, which ensures predictable script execution. Setting fireSlavingSync to true forces the client script to wait on any specified sourcing before continuing with the rest of the script.A common reason for issues with expense lines is interference from the Tax Nexus. If synchronous mode (i.e., fireSlavingSync: true) is not used, setting the tax code value may not allow the Tax Nexus to fetch the necessary tax code information. This can prevent the line from being successfully saved.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
