I've made templates for Quotes/Invoices the same way for a while. Trouble is, it can be pretty slow at times.
Currently, I create a separate table for templates. It has a join table(Template Line Items) that is connected to products in the same manner as an invoice line items t.o. would be. When I want to bring a template's line items into a quote, I use ExecuteSql() to nab the products' primary keys from that specific template's line items in the correct sort order. Then I run a loop to insert them into the quote's line items. It works. However, on my computer, it clocks about 20 seconds for the script to run. Needless to say, a lot of sales guys out in the field get pretty impatient with it.
How can I rebuild this template mechanism to make it fast?