ANS-0604 · SUITESCRIPT DEVELOPMENT
Why Does Post Sourcing Trigger Multiple Times on Line Item Selection in NetSuite?
Filtered List/Record custom columns on sublists can cause multiple, unexpected triggers of the Post Sourcing event in NetSuite.
Short answer
The NetSuite `post_sourcing` event triggers multiple times when selecting an existing line item due to List/Record custom columns filtered by the Item column. These custom fields re-evaluate filters and re-populate values, re-triggering the sourcing event. A common workaround moves related logic to the `fieldChange` event.
Scenario
Users observe that the `post_sourcing` event is triggered multiple times when an existing line item is selected on a transaction sublist. This behavior can lead to unexpected script executions or performance issues. The issue specifically arises when custom fields are present on the sublist.
Solution
NetSuite Support has confirmed that this behavior is intended. The Post Sourcing event is being triggered multiple times when an existing line is being selected because of custom fields that are configured to filter the values that they will show. What happens in the backend is that, after a custom field filters the expected values it will populate, it will then set these values to the List/Record type of field and since these fields are sourcing, the Post Sourcing event will be triggered. So, once a line item is selected, the custom field will check its filters again for it to know the values it will show, leading to repeated post_sourcing triggers. While removing the filtering on these custom columns would prevent the multiple triggers, it would necessitate calling multiple saved searches (one for each filtered column) every time a line is selected to properly filter the fields by script, which may introduce significant complexity or performance overhead. A current best practice workaround is to move the associated logic from post_sourcing to the fieldChange event, as fieldChange is not called multiple times in this scenario. This approach may carry a risk of potential timing issues depending on the specific implementation.
Expert NetSuite Support
Need help with this NetSuite issue?
SuiteScript Development consulting and configuration support
