Hi,
I have been thinking that there should be a sensible way to copy (duplicate) all of the line items on a transaction record (such as an invoice) using a Client Script, but have not been to accomplish this yet.
Logically, I thought that looping through all of the items on the current record object and duplicating each one would be the simplest. In order to avoid manually specifying each and every single field to be updated and set to a value, I thought I would try using the NetSuite method of copying line items...item_machine.copyline().
The part I don't understand is why looping through items and calling this code seems to be extremely slow. It takes ~4 minutes to copy 40 line items. I can copy them almost as fast by manually clicking.
Has anyone ever tried this or something similar? I would imagine this shouldn't be hard to do...do I really need dozens of lines of code to do a conceptual one-liner?
for (var i = 1; i <= itemCount; i++) { //Use the NetSuite API to select the line item number corresponding to this loop's iteration counter. nlapiSelectLineItem('item',i); //Duplicate a line item using the built-in NetSuite copy function to duplicate the line item! //This function is normally called by the "Make a Copy" UI button. item_machine.copyline(); }