After some testing, I found that when updating estimate line items, you’ll want to bulk your requests. Loading and saving the estimates is very timeconsuming. So load the estimate, make all your updates to line items and then save the estimate. This becomes a problem if you are removing a subset of items. Here’s how I accomplished the task.
- My example is in SuiteScript 2.0
- I’m removing 3 non-consecutive lines (Lines 1, 2 & 4).
- In my example, the lines I wish to remove are not supplied in order.
- You must do this in Dynamic mode. If you are unfamiliar with the 2 modes in SuiteScript, standard and dynamic, dynamic mode loads all the sublist items when you load the main (estimate) record.
- I’m removing Estimate Lines. Each line gets a line number. All sublists work the same.
- SuiteScript 2.0 references line numbers starting with a zero-based index. Note: This differs from SuiteScript 1.0 which is one-based.
- DON’T MISS THIS. Loading an estimate (in my environment) takes 4 seconds. Saving the estimates adds another 4 seconds. So I want to load the estimate, remove lines, and then save the updated estimate. This eliminates lots of overhead!!!
- When you remove a line, it changes the subsequent line numbers. So remove items from bottom to top in the list! You can ignore this if you are removing all lines. In that case, you can simply loop through all items, repeatedly removing line 0 (or 1 in SuiteScript 1).
- I’ve included the save() function, written for both client-side and server-side. Client-side is commented out.
- Finally, this example is meant for debugger. It uses require() instead of define().
Here is the code.
Here is the code in a form you can cut and paste into debugger.