Dynamically Evaluate Text as a Formula

Dynamically Evaluate Text as a Formula

When designing forms, the designer usually creates formulas in the Dynamic Value property of fields to perform calculations, string manipulation, or logic to achieve desired results. But what if a different formula is needed based on user input when filling out a form? You could accomplish this with lengthy nested IF() conditions or toggle field visibility per formula, but there's a much simpler dynamic approach.

With the ability to evaluate text as a formula, you could have a data source containing multiple formulas (as text) from which an app user can select to determine which formula to use. Then, an EVAL() function in another field's Dynamic Value evaluates the selected text as a formula with form-captured data.

TABLE OF CONTENTS


EVAL() Function Explained

EVAL(formula , {{field1}} , {{field2}} , {{field3}} , ... , {{fieldN}})

The function has two parts: A formula and form field data names. 

The formula part requires a formula, whether math, text, logic, etc., and must contain numeric placeholders that indicate which field value to use. Field values come after the formula as a comma-separated list of form field data names.

EVAL("{{0}} + {{1}}" , {{field1}} , {{field2}})

Where {{0}} is replaced with the value of {{field1}} and {{1}} is replaced with the value of {{field2}}.

Note that the formula is encased in double-quotations.

Alternatively, if the formula text was in the 2nd column of a data source and the linking field had a data name of formulaDS.

EVAL({{formulaDS[1]}} , {{field1}} , {{field2}})

This data source could be linked to the form with a Choices or Data Source field. To determine which formula to use, a user would need to select an option from the Choices field, or the Data Source would have filtering.


Examples

With a single EVAL() function in a form and a data source with three formulas, a user could decide whether to add, subtract, or multiply two numeric values. The image below depicts an in-app display with the respective field property configurations.

Result - Dynamic Value

EVAL({{formulaDS[1]}} , {{value1}} , {{value2}})

Data Source

Value - Column 0Label - Column 1
1{{0}} + {{1}}
2{{0}} - {{1}}
3{{0}} * {{1}}

Additional Formula Examples

Text (Formula)Dynamic Value With Data Source
IF({{0}} = 'Yes', 'True', 'False')
EVAL({{DS[1]}} , {{field1}})
CONCAT({{0}}, ' and ', {{1}})
EVAL({{DS[1]}} , {{field1}} , {{field2}})
FORMAT-DATE({{0}}, 'yyyy-MMM-dd')
EVAL({{DS[1]}} , {{field1}})
SUBSTITUTE({{0}}, 'name', 'title')
EVAL({{DS[1]}} , {{field1}})
IF({{0}} + {{1}} >= {{2}}, 'Pass', 'Fail')
EVAL({{DS[1]}} , {{field1}} , {{field2}} , {{field3}})


    • Related Articles

    • Dynamic Output using Form Formula

      TABLE OF CONTENTS Using Excel's Built-In Formulas Outputting Multiple Choice Fields Outputting Hyperlinks Using Word/Excel Comments to Preserve Template Formatting The platform has the ability to evaluate formulae just like those you would use in ...
    • Text Field

      TABLE OF CONTENTS Basic Properties Data Name Title Text Hint Text Layout & Styling Field Layout Background Color Text Lines Placeholder Text Validation & Behavior Required Visibility Dynamic Value Read Only Custom Validation Validation Message Answer ...
    • Creating a Formula

      Most advanced Form functions involve the use of a formula. As such it is critical that you understand how to create a formula to get the most out of our advanced features. Field Data Names First off you need to know how to address or refer to a field ...
    • Dynamically Displaying Images from Data Source, Web or Map sources

      TABLE OF CONTENTS Data Source-hosted Images Displaying an Image in a Media Field via a Choices Field Displaying an Image within a Section Field Web-hosted Images Location-based images The "Dynamic Image" property allows you to load images dynamically ...
    • Common Formula Q&A

      Below is a list of common scenarios that involve the use of a formula to achieve. This is purely a quick reference guide in a Q & A format. For more comprehensive explanations including worked examples, please refer to the rest of our Recipes. Q: How ...