Evaluate Text as a Formula

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 achieve 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) that an app user can select from 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.


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 {{1}} is replaced with the value of {{field1}} and {{0}} 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 must select an option from the Choices field, or the Data Source field 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

    • 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 ...
    • Formula Cheat Sheet

      Below is a comprehensive list of Appenate’s formula functions that can be used in various field properties throughout the platform, wherever the hammer icon is present. CONTEXTUAL USEREMAIL() User’s Email Address. USERFIRSTNAME() User’s First Name. ...
    • Formula FAQs

      Below is a list of common scenarios that involve using a formula. This is purely a quick reference guide in a Q&A format. For more comprehensive explanations, including worked examples, please refer to our Recipes. Question 1 How do I move fields ...
    • 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. Q: How do I move fields between Pages in the Form Designer? A: There are a few ways to do this: You can use ...
    • Formula Cheat Sheet

      Below are a list of most of the platform formula builder functions that can be used in formulae. 1. CONTEXTUAL FORMULAS TODAY() Current Date The current local date reported by the device. NOTE: Device dates can be inaccurate if the local time is not ...