Written by: | Christian Tratz |
Our formulas are used to calculate the results but at the same time also serve as configuration mechanism to drive certain UI elements, such as necessary input parameters.
Syntax Check Mode
To avoid the need to declare input parameters explicitly (they show up as you start using/expecting them in the formula), a mechanism called “syntax check mode” is used.
As the name implies, it not only determines inputs but also checks the formula for syntactical validity. This is e.g. the reason why a formula is executed in that mode once before saving it to prevent invalid formulas to be saved.
During such a syntax check execution, it is good to know:
- As formula inputs may actually be no real inputs as their data e.g. comes from previous calculation steps, the formula returns a default value for every input it encounters during this syntax check mode.
- This way the formula engine can in the end distinguish between “real” inputs (that it then needs to render to the user) and inputs that are fed by other formula elements (and do not trigger a UI element to be shown).
As you can see, determining inputs and executing formula are two calculation passes of the same “thing”. To not have negative performance impact, the syntax check passes are only done when required.
This is particularly relevant in e.g. a quote context. Here the input determination is only executed when the item is added to the quote; not every time the quote is recalculated.
If you require dynamic inputs that depend on other data or should change based on some other changes, you need to handle that either by header formulas (which can manipulate inputs) or use a configurator approach.
As a best practice, input parameters should be high up the logic, with no or as little as possible dependencies / conditional logic on them.
The reason is that the very same logic that is used for outputs computation is also used for parameter determination. You can use following example shows how the api.isSyntaxtCheck()
API call is used to determine which determines which code does not need to be run in the parameter determination mode and should be called only in the real computation (like expensive DB calls).Example:
Code Block |
---|
def inputVal = api.userEntry() if (api.isSyntaxCheck()) return; def costs = api.find("PX", equal("name", "costs")) |
...