KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: 4D Formulas and Variable Scopes
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: September 19, 2023

When calling a formula, it is executed in the current process. This means that some variables from the calling method can be applied to the formula. However, there are some limitations based on how the formula is created.

For example with the following code, the results for all three ALERT dialogs should be the same for each execution of the code:

ALERT(String(Current process name))

$fomula:=Formula(ALERT(String(Current process name)))
$fomula.call()

$fomulaFrStr:=Formula from string("ALERT(String(Current process name)))")
$fomulaFrStr.call()


For both uses of the Formula... commands, a process variable can be accessed:
stringVar:="Hello World"

$fomula:=Formula(ALERT(stringVar))
$fomula.call()

$fomulaFrStr:=Formula from string("ALERT(stringVar)")
$fomulaFrStr.call()
The code above will run without issues.

A limitation of the Formula from string command is that it cannot reference a local variable, while the Formula command can:
$stringVar:="Hello World"

$fomula:=Formula(ALERT($stringVar))
$fomula.call()

$fomulaFrStr:=Formula from string("ALERT($stringVar)")
The first formula will run properly, but when trying to create the Formula from string, a Syntax Error will occur: