0

Need help with a loop, do script

I made a database for listing jewelry items and forming "linesheets" and invoices that have specs, a photo of items, the wholesale and retail prices. Items for linesheets are selected from the "Articles" table and assembled in the "InvItems" subtable, then printed to various templates.

The "Articles" table has pricing data for each item, "WScur" - Wholesale Current Price & "RETLcur" Retail Current Price --both of which are updated as prices fluctuate. However, I need to "fix" these prices for issued Invoices and Linesheets by copying the "current" dynamic prices into "fixed" number fields "WSfix" and "RETLfix" ... so issued documents remain as issued, unless I choose manually overide with the updated price.

I made a button script that works well with a modest number of items (under 20), but it gets completely hammered (hangs for over an hour) when the list is 100-200 items (a full product listing) ...

let Zcnt := 1;
for Zql in InvItems[Article.itemCatg = 1 and WSfix = null] do
    InvItems.(WSfix := Article.WScur);
    for Zql in InvItems[Article.itemCatg = 1 and RETLfix = null] do
        InvItems.(RETLfix := Article.RETLcur)
    end;
    Zcnt := Zcnt + 1
end

The modifiers "Article.itemCatg = 1" limits the script to "products" and "WSfix = null" prevents overwriting the prior Wholesale Price (if there was one).

My Question: how can I do this function either with (a) a more efficient looping script (maybe there's an error here), or (b) avoid the loop construct altogether? I prefer a button activated script as opposed to a "triggered" script, largely because I can't figure out where the trigger script should live (beyond my experience). 

I've attached a screenshot of the "InvItems" subtable with some notes.

Many thanks in advance for thoughts/advice.

Bob

Reply

null

Content aside

  • 6 hrs agoLast active
  • 5Views
  • 1 Following