Sum Function in Scripts

Setup: FMS19, FMP19, Win 10

My point-of-sale (POS) system runs a “set total of sale” script after each item is added to a sale. This script calculates the city and county taxes, line total, and sale total. The POS has a preferences table with multiple options/parameters for setting the tax rate (e.g., by company, location, workstation, etc).

Therefore, the script is somewhat complex, with many if/else if branches depending on the tax methodology being used. The script makes liberal use of the SUM function to calculate these totals. My goal is to make this script run faster.

QUESTION: When executing a script, does FMP19 evaluate “all” of the SUM functions in every branch — regardless of whether it’s the “correct” branch — or just the branche(s) that correspond to the preferences I’ve set? (Logically, I’d think only the branches being executed would be evaluated; however, I don’t know if this is how the engine actually works.)

For "if" Script step, the calculation is only performed when needed.

You can trace this with using e.g. our MBS("Log"; "test") call to log various things.
Maybe that could help to log how long some parts of the script take long and then calculate where it takes longest.

2 Likes

If you need speed, I would say don't use calculated fields and compute the values inside the script. It's faster.

1 Like

That’s what I’m looking at now. I’m going to replace the most egregious unstored calculations with static fields that are updated via scripts.

I thought unstored calculations were causing this script to run slowly (1.85 seconds) but it’s not referencing them.

Regardless, I’m going to strip this script down to just the few lines I need and see how that affects performance.

Consider using custom functions for the various tax rates.

1 Like