ANS-0323 · CUSTOM FIELDS, RECORDS & FORMS
How to Prevent Subtotal Calculations on Deleted NetSuite Line Items?
Implement a client script and a hidden custom field to control subtotal calculations, ensuring they do not apply when line items are removed from a sublist.
Short answer
To prevent subtotal calculations from applying after a line item is deleted, create a hidden custom body field to store the line item count. Use a client script's validateDelete entry point to capture the count before deletion and the sublistChanged entry point to compare counts, conditionally skipping subtotal logic if a line item was removed.
Scenario
Users may encounter situations where subtotal calculations on a NetSuite record should not apply if a line item has been deleted from a sublist. This often occurs when custom calculations are tied to the number of line items, and simply removing a line item should not trigger a recalculation of the subtotal based on the previous count.
Solution
To manage subtotal calculations when line items are deleted, follow these steps:
Create a custom body field of type integer and ensure it is hidden. This field will temporarily store the line item count.
Implement a client script and, within its
validateDeleteentry point, set the custom hidden body field with the current number of line items on the sublist.At the beginning of the client script's
sublistChangedentry point, retrieve the value of the custom hidden body field and the current number of line items on the sublist.Compare these two values. If the current number of line items is less than the value stored in the custom field, it indicates a line item was deleted. In this specific case, do not apply the subtotal calculations.
At the end of the
sublistChangedentry point's logic, update the custom hidden body field with the current number of line items. This ensures the field is correctly reset for subsequent changes and prevents unintended behavior in other calculation scenarios.
Expert NetSuite Support
Need help with this NetSuite issue?
Custom Fields, Records & Forms consulting and configuration support
