Imagine you have a list of formulas containing table names and some fields … then days later you decide to rename your tables. Now your formulas are no longer valid, which is totally understandable!
Well, good news: the new Parse formula command allows your formulas to remain valid when renaming 4D language or structure elements.
This command makes it possible to transform the contents of a 4D formula into different formats. For example, a formula containing the name of a table and a field can be transformed into a formula containing the corresponding virtual structure and vice versa.
It also lets you tokenize or detokenize a formula. This makes it possible to save a user-defined formulas by converting it to its tokenized format. You can then display the formula in a detokenized format without worrying about problems caused by changing a table or field name.
code snippet
Here is an example of this command in action:
// ask the user to type their favorite formula
$formula:=""
EDIT FORMULA([Table_1];$formula)
// save the formula for later use
CREATE RECORD([users_preferences])
$persistentFormula:=Parse formula($formula;Formula out with tokens)
[users_preferences]formula:=$persistentFormula
// later: execute the previously saved formula
CREATE RECORD([Table_1])
EXECUTE FORMULA([users_preferences]formula)
And voilà, no more invalid formulas!