FORMULA WIDGET KT DEMO SCRIPT
FORM TEMPLATES TO PREPARE
Template 1: Basic Calculator
| Field Name | Field Type |
|---|---|
| Price A | Number |
| Price B | Number |
| Total | Formula → @Price A + @Price B |
Template 2: Bulk Discount Calculator
| Field Name | Field Type |
|---|---|
| Quantity | Number |
| Unit Price | Number |
| Discount | Formula (USE RULES) |
| Formula name: "Discount Calculator" | |
Rule 1 name: "20% Bulk Discount", Condition: Quantity > 100, Formula: @Quantity * @Unit Price * 0.8 | |
Rule 2 name: "10% Medium Discount", Condition: Quantity > 50, Formula: @Quantity * @Unit Price * 0.9 | |
Default Formula name: "No Discount", Formula: @Quantity * @Unit Price |
Template 3: Expense Report
| Field Name | Field Type |
|---|---|
| Day 1 | Matrix with columns: Food (Number), Transport (Number), Accommodation (Number) |
| - Add 2 rows (NOT iterative mode) | |
| - Turn ON "Row Sum" aggregation for the row (creates Row1_Total, Row2_Total cells) | |
| Day 1 Total | Formula → @Day 1_Row1_Total + @Day 1_Row2_Total |
| Day 2 | Matrix with columns: Food (Number), Transport (Number), Accommodation (Number) |
| - Add 2 rows (NOT iterative mode) | |
| - Turn ON "Row Sum" aggregation for the row | |
| Day 2 Total | Formula → @Day 2_Row1_Total + @Day 2_Row2_Total |
| Total Expense | Formula → @Day 1 Total + @Day 2 Total |
| Number of Days | Number (default value: 2) |
| Daily Average | Formula → @Total Expense / @Number of Days |
| Note: Since formula uses ROW aggregates, we CANNOT enable Iterative Mode for this matrix |
Template 4: Date Calculator
| Field Name | Field Type |
|---|---|
| Start Date | Date |
| End Date | Date |
| Duration (Days) | Number |
| Projected End | Formula → @Start Date + @Duration (Days) |
| Days Between | Formula → @End Date - @Start Date |
Template 5: Validation Demo
| Field Name | Field Type |
|---|---|
| Credit Score | Number |
| Loan Status | Text (helper field - validation set HERE, condition checks Credit Score) |
Validation: Credit Score < 650 → Error: "Credit score too low for this loan" | |
| Loan Amount | Number |
Template 6: Number Types Demo
| Field Name | Field Type |
|---|---|
| Base Amount | Number (Currency: INR) |
| Discount Rate | Number (Type: Percentage) |
| Discount Amt | Number (Currency: INR) |
Formula: @Base Amount * @Discount Rate | |
| Final Amount | Formula → @Base Amount - @Discount Amt |
INTRODUCTION
Good morning/afternoon everyone. Today I'm going to show you the Formula Widget in DynaForms.
DynaForms powers all the data entry screens in our application - forms where you enter information, run calculations, and submit data.
The Formula Widget is what makes those calculations happen. I'm going to show you what it can do, and the safety guards we've built in to prevent data corruption.
Let's begin.
BASIC FORMULA
DO: Open Form Template 1: Basic Calculator
I'm starting with a simple form. Two number fields - Price A and Price B. And a formula field called Total that adds them together.
DO: Click on the Total formula field to show the formula in the right panel.
This is the formula: Price A plus Price B. The @ symbol means "the value of this field". So the formula takes Price A, adds it to Price B, and puts the result in Total.
DO: Click Validate. Show the green checkmark.
Green means the formula is valid.
DO: Switch to Preview mode.
Here's the form as users would see it.
DO: Enter 100 in Price A, 50 in Price B.
Total automatically calculated to 150. The user just enters the numbers, the formula does the work.
Now let's see what happens when we need different formulas for different situations.
RULES-BASED FORMULAS
DO: Open Form Template 2: Bulk Discount Calculator
This is where it gets interesting.
Imagine you're running a store. When customers buy in bulk - say more than 100 items - you give them 20% off. For medium orders above 50 items, you give 10% off. Smaller orders get no discount.
With a single formula, you only get one calculation. But with Rules, you can have DIFFERENT formulas for DIFFERENT situations based on MATHEMATICAL CONDITIONS.
DO: Click on the Discount formula field.
I need to give this formula a name so it's easy to identify. I'll call it "Discount Calculator".
DO: In the Formula Library panel, click to edit the formula name. Type "Discount Calculator".
Now let me enable Rules.
DO: Toggle "Use Rules" switch to ON.
The system moved my existing formula into a Formula Library. The default formula is now named "No Discount" - it applies when no other rules match.
Now let me add the first rule for bulk orders.
DO: Click "Add Rule", then configure:
- Rule Name: "20% Bulk Discount"
- Condition: Quantity > 100
- Formula:
@Quantity * @Unit Price * 0.8
I've created a rule that says when Quantity is greater than 100, apply 20% discount.
Now let me add another rule for medium orders.
DO: Click "Add Rule" again, configure:
- Rule Name: "10% Medium Discount"
- Condition: Quantity > 50
- Formula:
@Quantity * @Unit Price * 0.9
DO: Show the Formula Library with the named formula, 2 named rules, and the default.
Now - an important feature. The ORDER of rules matters.
DO: Switch back to edit mode. Show the rules list with drag handles.
These rules are evaluated from top to bottom. The first rule that matches wins.
DO: Demonstrate dragging "10% Medium Discount" above "20% Bulk Discount".
Wait - if I put Medium Discount first, there's a problem. Let me show you.
DO: Drag Medium Discount to the top position.
Now Medium Discount comes before Bulk Discount. When Quantity is 150 - which is greater than both 50 AND 100 - the system will check Medium Discount first. 150 is greater than 50, so it matches Medium Discount and applies 10% discount. It never reaches the Bulk Discount rule.
The order matters! 20% discount never gets applied because 10% catches it first.
DO: Drag Bulk Discount back to the top to restore correct order.
DO: Drag "No Discount" to the top - show that this breaks everything because it matches all quantities.
DO: Drag it back to the bottom where it belongs.
This is why we have a Formula Library - to organize all your conditional formulas and their priority.
DO: Switch to Preview/Renderer mode.
DO: Enter Quantity = 10, Unit Price = 100.
For a small order of 10 items - no discount - total is 1000.
DO: Change Quantity to 75.
Same products, same price - but now it's a medium order, so 10% discount - total is now 6750.
DO: Change Quantity to 150.
Now it's a bulk order - 20% discount - total is 12000.
Different quantities, different discounts, all handled by one field that automatically picks the right formula based on the mathematical conditions.
MATRIX FIELDS
DO: Open Form Template 3: Expense Report
Matrix fields are like mini-spreadsheets inside your forms. Rows and columns of data.
Here I have an Expense Report for two days - Day 1 and Day 2. Each matrix has columns for Food, Transport, and Accommodation.
DO: Show the Day 1 matrix settings.
Important setup step: I have added 2 rows to each matrix. And I have turned ON "Row Sum" aggregation - this creates automatic Total cells for each row.
This means the matrix automatically calculates the sum of all columns for each row - Row 1 Total and Row 2 Total.
DO: Click on Day 1 Total formula field.
This formula uses the row total cells. It adds Row 1 Total plus Row 2 Total - the row aggregates, not the individual cells.
This is cleaner than adding individual cells - the matrix handles row additions automatically via the row aggregate.
DO: Click on Day 2 Total formula field.
Same approach - using the row aggregate cells.
DO: Click on Total Expense formula field.
Day 1 Total plus Day 2 Total equals Total Expense.
DO: Click on Daily Average formula field.
Total Expense divided by Number of Days.
DO: Switch to Preview/Renderer mode.
DO: Enter in Day 1 Row 1: Food = 500, Transport = 200, Accommodation = 1000. DO: Enter in Day 1 Row 2: Food = 300, Transport = 150, Accommodation = 800.
Row 1 Total is 1700. Row 2 Total is 1250.
Day 1 Total is 2950. 1700 plus 1250.
DO: Enter in Day 2 Row 1: Food = 400, Transport = 100, Accommodation = 900. DO: Enter in Day 2 Row 2: Food = 200, Transport = 50, Accommodation = 500.
Day 2 Total is 2150.
Total Expense is 5100. 2950 plus 2150.
Daily Average is 2550. 5100 divided by 2.
The row aggregates react automatically when I change row values. This makes formulas resilient.
Now here is an important safety guard about matrices.
DO: Switch back to edit mode. Click on Day 1 matrix settings.
DO: Look for "Iterative Mode" toggle. Try to enable it.
The system blocks it! Error says: Cannot enable Iterative Mode. Static row cells are currently used in formulas: Day 1 Total.
Why? Because my formula uses row aggregate cells like Row 1 Total and Row 2 Total. These are "static" - they exist only for the rows I created. If the matrix were iterative - meaning users could add unlimited rows dynamically - there would be no way to know which row cells to reference.
We prevent this conflict to keep your formulas working correctly.
DATE CALCULATIONS
DO: Open Form Template 4: Date Calculator
Dates are tricky in calculations. We've made them work naturally.
Here I have Start Date, End Date, and Duration.
Let me show you two types of date calculations.
DO: Click on Projected End formula field.
This formula is Start Date plus Duration in days. Date plus Number equals Date. The system treats raw numbers as Days when added to or subtracted from a date. Useful for calculating a future date.
DO: Switch to Preview mode.
DO: Select Start Date = March 1, 2026. Enter Duration = 30.
Projected End is March 31, 2026. The system understands that adding days to a date should give another date.
DO: Click on Days Between formula field.
This formula is End Date minus Start Date. Date minus Date equals Number. This gives the number of days between two dates.
DO: Select End Date = March 15, 2026.
Days Between is 14. March 1 to March 15 is 14 days.
But here is an important safety rule.
DO: Switch back to edit mode. Try to create a formula: @Start Date + @End Date
DO: Click Validate.
The system blocks this. Why? Because adding two dates together doesn't make mathematical sense. What would March 1 plus March 15 even mean?
This is one of our safety guards - we prevent invalid operations.
NUMBER TYPES
DO: Open Form Template 6: Number Types Demo
Numbers can be more than just plain numbers. They can have types.
Here I have Base Amount as a Currency field with INR symbol. And Discount Rate as a Percentage field.
The Percentage type is special. When a percentage field is used in a formula, the system automatically divides by 100.
DO: Click on Discount Amount formula field.
This formula is simply Base Amount times Discount Rate.
DO: Point to the formula input box.
Notice that I'm NOT dividing by 100 here. Since Discount Rate is a Percentage type, the system handles the conversion automatically behind the scenes.
DO: Click on Final Amount formula field.
Base Amount minus Discount Amount.
DO: Switch to Preview mode.
DO: Enter Base Amount = 10000, Discount Rate = 15.
Discount Amount is 1500. That's 10000 times 15 divided by 100.
Final Amount is 8500.
DO: Change Discount Rate to 10.
Discount Amount is now 1000. 10000 times 10 divided by 100.
Final Amount is 9000.
The system handled the percentage conversion automatically. You don't have to manually divide by 100 in your formula.
This works for any percentage calculation - tax rates, discount percentages, growth rates, all of them.
VALIDATION RULES
DO: Open Form Template 5: Validation Demo
Formulas aren't just for calculations - they can enforce business rules.
Here is a loan application form with Credit Score and Loan Amount fields. I need to check if the applicant qualifies based on their credit score.
I have a helper field called Loan Status. The key rule is: a field cannot reference ITSELF in its own validation condition. So I set the validation on Loan Status, and the condition checks the Credit Score field.
DO: Click on the Loan Status field. Scroll to show the Validation Rules section in the right panel.
DO: Click "Add Validation Rule", configure:
- Condition: Credit Score < 650
- Error Message: "Credit score too low for this loan"
Now let me show you how it works.
DO: Switch to Preview mode.
DO: Enter Credit Score = 720, Loan Amount = 500000.
No error - validation passes because Credit Score is above 650.
DO: Change Credit Score = 580.
The system shows the error: Credit score too low for this loan. The applicant's score is below the threshold.
DO: Change Credit Score = 650.
No error - exactly 650 is acceptable.
Useful for eligibility checks, credit assessments, business rule enforcement. It happens in real-time as users fill out the form.
SAFETY GUARDS
Now the most important part.
When we built the Formula Widget, we thought about what could go wrong and built protection against all of them.
Multiple layers of safety guards to ensure data stays consistent and forms never break.
We've already seen some of these in action:
- Date addition is blocked because it makes no mathematical sense
- Cannot enable Iterative Mode when formulas reference row aggregates
Let me show you more.
GUARD: Matrix Row Cannot Be Deleted
DO: Go to Form Template 3: Expense Report. Right-click on Row 1 of the Day 1 matrix, click Delete.
The system blocked it. Error says: Cannot delete row. Its cells are currently used in formulas.
This prevents broken formulas. If you could delete this row, the formula would reference nothing and show incorrect results.
GUARD: Row Aggregate cannot Be Disabled
DO: Try to diable the Row Aggregate toggle from Day 1 matrix.
Cannot disable it because it's being used in formulas. Same protection as rows.
GUARD: Number Type Cannot Be Changed
DO: Go to Form Template 1: Basic Calculator. Click on Price A field. Open the Number Type dropdown.
This field is NOT used in any formulas, so I can change it.
DO: Now go to Form Template 6: Number Types Demo. Click on Base Amount field (which IS used in formulas). Try to change Number Type.
Blocked. Cannot change number type because this field is currently used in formulas.
If you change a number to a percentage, the formula might produce unexpected results. We've protected you from accidentally breaking calculations.
GUARD: Cannot Delete Field Used In Other Formulas
DO: Go to Form Template 6: Number Types Demo. Try to delete the Base Amount field.
Cannot delete it. It is referenced in formulas on: Discount Amt, Final Amount.
The system tracks ALL dependencies. You cannot accidentally delete something being used elsewhere.
GUARD: Cannot Set Formula As Default When Used In Rules
DO: Go to Form Template 2: Bulk Discount Calculator. Click on Discount formula field (which has rules configured). Try to set it as the default formula.
The system shows a modal explaining I cannot set it as default because it's already being used in conditional logic.
This prevents conflicts where one formula might behave two different ways.
GUARD: Cannot Mix Different Currencies
DO: Create a new number field with Currency: USD. Try to create a formula: @Base Amount + @USD Field.
The system blocks it. Formula cannot mix different currency types (e.g., USD and INR). We enforce that all values in a formula must use the same currency.
Note: You CAN safely mix Currencies with Percentage fields or raw numbers (depending on the operation), but you cannot mix two different actual currencies.
GUARD: Stale Reference Detection At Save Time
DO: Open a form with chained formulas where one formula references another, and modify one of the rules to return a different output type.
DO: Try to save.
The system detects this at save time and blocks the save.
Error says: This formula references another formula which has inconsistent output types across its rules.
Most systems only detect this when the form runs and shows errors to users. We catch it at save time, before it ever becomes a problem.
So those are our safety guards:
Matrix rows and columns cannot be deleted if used in formulas. Number types cannot be changed if the field is referenced. Formulas used in rules cannot also be set as default. Fields cannot be deleted if used in other formulas. Different currencies cannot be mixed. Iterative mode cannot be enabled if formulas reference row aggregates. Stale references are caught at save time.
Plus our automatic label handling that prefixes numeric-starting labels with "f" to keep formulas working. Plus our automatic percentage conversion that divides by 100 when using Percentage type fields.
This is what we mean by production-grade. We've thought through every way a formula could break and protected against all of them.
Questions?
ERROR MESSAGES QUICK REFERENCE
| When you try to... | System says... |
|---|---|
| Delete matrix row | Cannot delete row. Its cells are currently used in formulas |
| Delete matrix column | Cannot delete column. Its cells are currently used in formulas |
| Change number type | Cannot change number type. This field is currently used in formulas |
| Set formula as default when used in rules | Cannot Set as Default - This formula is currently assigned to rules |
| Delete field used in formulas | This field is referenced in formulas on: [formula name] |
| Mix currencies | Formula cannot mix different currency types |
| Add two dates | Adding dates is not allowed |
| Enable iterative mode with row agg refs | Cannot enable Iterative Mode. Static row cells are currently used in formulas |
| Save with stale reference | [Formula] references [other formula] which has inconsistent output types across its rules |
| Import template with numeric-starting labels | Auto-fix available: Some field labels start with numbers |
(End of file - total 535 lines)