Platform
Chatbot Builder Bulk Messaging Team Inbox Mini CRM API & Webhooks AI Integration WhatsApp Flows
Industries
E-commerce & D2C Real Estate Education Healthcare Finance & BFSI Logistics Hospitality Retail
Integrations
Learn
Learning Hub Help & Docs Connect Guides Automation Codex Blog Message Templates
Pricing Get Started →
HomeHelp & DocsMini Apps › Conditional calculations and dynamic logic in Mini Apps
Mini Apps

Conditional calculations and dynamic logic in Mini Apps

WhatsApp Flows support conditional field visibility and calculated totals, but the calculation part works differently from a typical form builder — it uses JavaScript ternary logic pasted into a data source, not a drag-and-drop formula field. This guide walks through both, using an event registration form as the example.

Conditional field visibility

Show fields only when a previous answer meets a condition — for example, showing "Person 2" details only if the customer selected 2 or more packs.

1
Add the field you want to conditionally show.
2
Set its visibility condition, e.g., show Person 2's fields when Number of Packs ≥ 2.
3
Repeat for each conditional field — Person 3 fields when Packs ≥ 3, Person 4 when Packs = 4.
Only works on input components

Conditional visibility only applies to input fields (text, dropdown, etc.) — not to text or heading elements.

Building the calculation

Say each visitor's pricing depends on whether they need a stay: ₹2500 if yes, ₹750 if no, ₹0 if the field isn't present at all.

1
Write out the logic in plain if-else first: If Stay = Yes → 2500. If Stay = No → 750. Else → 0.
2
Convert this into a JavaScript ternary expression. For multiple people, add a ternary block per person and sum them all.
Use AI to write the ternary syntax

Prompt ChatGPT with something like "write this logic using a ternary operator in JavaScript." Copy only the formula it returns, then swap in your dynamic field variables in place of the static example values.

Adding it to your Mini App

1
Add the calculation logic on the same screen where the result needs to display — typically a summary screen.
2
Replace the placeholder variables in your formula with the actual field mappings from earlier screens.
3
Save the calculation as a data source.
Critical: the Run & Save trick, and when to stop using it

Before entering your real formula, add a placeholder test calculation (e.g., 4 + 4) and click Run & Save. This unlocks the output field in history. Now replace the placeholder with your actual formula and map it into the text or body field. Do not click Run & Save again once the real formula is in place — there's no live form data available at that point, and re-running it breaks the mapping.

Displaying the results

You can display any combination of the calculated values — total packs, packs with stay, packs without stay, total payable amount — all dynamically pulled from your calculation fields on the summary screen.

Key tips

Write the logic in plain language first, then convert to a formula — don't try to write the ternary directly.
Reference dynamic variables from earlier screens rather than hardcoding values.
Keep the calculation on the same screen where its output is shown.
WhatsApp's Flow UI has limited visual formatting — use dotted lines or spacing in text to separate sections since there's no divider component.

Was this helpful? If you are stuck, message us on WhatsApp and a real person will help.

Ask us on WhatsApp
Related guides
1