How to Create Conditional Logic in Calculations Using IF Statements
Learn how to create conditional logic in calculations using IF statements in Smarter Drafter Pro.
Conditional logic in calculations allows you to perform different actions based on specific conditions. Using the IF statement in Smarter Drafter, you can customise your form to show or calculate values based on user input. This is useful for creating dynamic forms that adjust their behaviour depending on the information entered. This guide will show you how to set up conditional logic using IF statements in your calculations.
Instructions
1. Open the form where you want to add conditional logic.
2. Create a New Field
- Click on Add Field to create a new field where the result of the conditional logic will be displayed.
3. Choose the Field Type
- Select the appropriate field type based on the result you want to output. For example:
- Number: For numeric results.
- Text: For text-based results, such as "Yes" or "No".
4. Set Field Properties
- Fill in the necessary properties for the field, such as the field name (e.g., "Discount Applied"). Set the field to Read-Only or Hidden, depending on whether you want the user to see the result.
5. Select the Calculation Tab
- In the field properties, click on the Calculation tab to open the Calculation Builder tool.
6. Click Start Here
- Click the Start Here button to open the Calculation Builder tool. This will help you set up the conditional logic.
7. Choose the Calculation Type
- In the Calculation Builder, select Conditional as the data type, and then choose IF as the calculation type. This will enable you to create conditional logic based on the user's input.
8. Write the IF Statement
- To create an IF statement, you will define the condition and the result for both the TRUE and FALSE outcomes. The basic structure of the IF statement is:
- IF condition THEN result1 ELSE result2
- For example:
- IF the user’s age is greater than or equal to 18, THEN show "Adult", ELSE show "Minor".
- The expression would look like this:
- IF Age >= 18 THEN "Adult" ELSE "Minor"
9. Insert the Condition
- Click on the Reference Field drop-down and select the field you want to use in the condition (e.g., "Age"). You can then insert the condition. For example:
- If you want to check if the user has agreed to terms, your condition could be something like:
- IF AgreeToTerms = true THEN "Agreed" ELSE "Not Agreed"
10. Save the Field
- After completing the IF statement, click Save to apply the calculation. The field will now display the appropriate result based on the condition you set.
11. Test the Conditional Logic
- Test the form by filling it out with different inputs. Ensure that the field displays the correct result based on the condition. For example, if the user’s age is 20, the field should display "Adult", and if the user’s age is 16, it should display "Minor".
Common Issues & Solutions
- Issue: The conditional logic is not working as expected
- Solution: Double-check your condition to ensure it is written correctly. Ensure that the field reference is correct and that the logic uses the right operators (e.g., >=, =, <=). Also, ensure the fields being referenced are correctly populated when the form is filled out.
- Issue: The result is not displaying the expected text or value
- Solution: Make sure the text inside the IF statement is properly quoted (e.g., "Adult"). Also, verify that the condition and the result values are correctly defined.