Dynamic Fields
Dynamic Field is currently in BETA
The dynamic field is a newly released field meant to address specific growth pains introduced in some growing apps. Please read this carefully to understand when and how to use it.
In a nutshell: The dynamic field is a read-only field that does not save any values to the database.
How does it work?
Generally, when you add a field to your data table, a new column is added to the database to store the value entered. This is the commonly recommended approach to managing your fields. However, as your app grows and you add more equations and fields, things can go slower when saving and updating records. Each time you save a record in the database, many behind-the-scenes actions ensure all the connections and calculated values are updated accordingly. While each action only takes a few (10-20) milliseconds, if you have 200 fields, that can translate into 4 seconds to save or update a record.
The dynamic field is unique since it does not save any values to the database. All calculations happen when the data is displayed, and some calculations (in forms, for example) will occur on the client side. This means that the "reads" will be slightly slower, but the writes will be much faster. We do this since reading from the database can be spread across many servers while writing requires that action to happen on the Single Primary Writer.
Why use a dynamic field?
There are primarily five reasons where a dynamic field can be a superpower.
- When your table hit the SQL limit of how many fields can be added to that table. The dynamic field can create several templates within the same area.
- When you have fields that are mostly being used to show a value on the app or API.
- When there are many equations and your forms are submitting slower than you'd like.
- When you have very complex queries and can use a Handlebars like syntax for these queries.
- When you want to show updated values in real time as a form is being updated.
Dynamic Field Limitations
Since we do not save any values to the database, this field will have the following implications:
- Values from dynamic fields are not searchable.
- Values in dynamic fields cannot be used for sorting and filtering.
- Dynamic fields cannot be included in other equations and formulas.
Using Dynamic Fields
Creating a Dynamic Field
To get started creating a dynamic field add the Dynamic Field located under Equation category:
Inside the field editor, you create your field output by combining Field Values with Dynamic Field Functions, HTML, text. Each output that you create inside of the field editor is called a Template.
Dynamic Field Functions can be loaded directly from the Snippets button located above the editor window. Field values can be added using the Add Field dropdown menu. When adding Fields to the editor, only the field ID will be present and not the field name.
Double curly braces must be used to initialize a function or field value. When functions and fields are nested, only 1 set of double curly braces should be used. For example:
👇 Output the value of field_123
{{field_123}}
👇Outputs the value of field_123 * 10
{{multiply field_123 10}}
👇 Outputs the value of field_123 * 10 with 2 decimal places
{{toFixed (multiply field_50 10) 2}}
Triple curly braces must be used to purposefully render HTML.
If you are storing HTML in a Long Text field, and want to output that HTML as text using the Dynamic Field, wrap the field_id in double curly braces - {{field_id}}
If you are storing HTML in a Long Text field, and want to output that HTML as rendered HTML using the Dynamic Field, wrap the field_id in triple curly braces - {{{field_id}}}
🔗 Check out all the available functions for the Dynamic Field
Viewing a Dynamic Field
After creating a Dynamic Field and Templates, you can add this field to Data Components as you would with any other field, with the exception of these additional features.
- You can add the same Dynamic Field to a component multiple times.
- After adding a Dynamic Field to a component, click to edit the field and select which template to display.
- When a Dynamic Field is added to a Form Component, the Dynamic Field will output in real-time as the Form Inputs change.
Check out the following example 👇
Problem: We want to show a total cost value in real-time as the User is selecting how many emails they wish to send.
Solution: Using the dynamic field, create a template to multiply the Number of Emails field * 0.001
The template will look like this:
${{toFixed (multiply field_50 0.001) 2}}
The template will render in the Data Builder using the Default Template.
In order to view the calculation in real-time, add the Dynamic Field to a Form Component.
In addition, by creating another template inside the same Dynamic Field, we can display a completely different calculation with no additional resources used by the system. When adding the Dynamic Field to a Form Component a second time, you can select which template to display.
We can then display both of the calculated outputs from a single Dynamic Field at the same time.
We'd love to hear your feedback.