Writing Conditional Statements
Logiforms supports an easy to use syntax for writing conditional statements using the common IF / THEN / ELSE structure. Below are some guidelines and examples. Conditional statements are always written in the Binding Editor.
On This Page
Formatting Guidelines
-
The value you are evaluating must be inside single quotes (ie. 'California').
-
When checking the value entered in a radio, checkbox or drop down the comparison is made against the "Data Value".
-
The field name must always match a field name on your form (ie. [STATE]).
-
You must have either the THEN or ELSEIF keyword at the end of every line that starts with IF.
-
You do not need the THEN keyword after the final ELSE statement as in the example below.
-
The ENDIF keyword must be included at the end of the statement and it must be as shown here.
-
If you are evaluating a number (e.g., IF [myfield] > 10) then you should not use quotes around the number.
-
All operators and operands should be written in uppercase (e.g AND, OR, IF, THEN, ELSE, ENDIF)
Examples
Example of an IF / THEN / ELSE statement:
Here's an example that show how to use the ELSE statement to perform a calculation when the IF statement does not evaluate to true.
IF [STATE] = 'California' THEN [tax]=[subtotal]*.07 ELSE [tax]=0 ENDIF
When using the ELSE statement, the next two rows must contain a calculation and then the ENDIF statement.
Example of an IF/THEN/ELSEIF statement:
Here's another example, in which multiple statements are evaluated. The statement is executes from the top down. When the first IF statement does not match, the next ELSEIF clause if run. If it matches, the calculation following the THEN keyword is executed. If there is no match, the next ELSEIF is run and so on. This repeats to the end of the statement. If there are no matches, and the statement includes a ELSE keyword at the bottom, the final calculation (the default) will execute.
IF [STATE] = 'California' THEN [tax]=[subtotal]*.07 ELSEIF [STATE] = 'Washington' THEN [tax]=[subtotal]*.05 ELSE [tax]=0 ENDIF
The IF/THEN/ELSE statement can be continued in this fashion to support an unlimited number of ELSEIF statements. You can also make the statements being evaluated more complex by using the two operators AND/OR while using parentheses.
Here is an example of
IF ([STATE] = 'California' OR [STATE] = 'OHIO') AND [CHARGETAX]='TRUE' THEN [tax]=[subtotal]*.07 ENDIF
Using WildCard Modifier Functions in Evaluations
Wildcard modifier functions can be used in the conditional statement to add additional evaluation options. For example, you can use the getYearsOld() modifier function around a Date of Birth field to calculate an age and then use it in an evaluation.
Assigning a WildCard Modifier Function
-
In the Binding Editor, highlight the wildcard to which you want to apply the modifier.
-
Click the functions button.
-
Select the modifier function.
-
In the binding editor, you'll see the modifier function wrap around the wildcard.
Here are some examples of conditions that use modifier functions:
IF getYearsOld([dob]) < 18 THEN 'We\'re Sorry, you are not eligible for this offer' ENDIF
This next example checks that at least 3 days (the minimum stay in this example) were booked:
IF getdaysinrange([Start Date],[End Date]) < 3 THEN 'A minimum of 5 nights is required' ENDIF
Checking TRUE/FALSE results from Modifier Functions
Many of the wildcard modifier functions return a true or false value, and you can use these in your conditional statements.
This example is correct:
IF isinlist([Favorite Cities],'Vancouver') = true THEN 'You selected that Vancouver is one of your favorite cities' ENDIF
However, this example would fail due to the quotes used around the true/false result:
IF isinlist([Favorite Cities],'Vancouver') = 'false' TH 'You selected that Vancouver is one of your favorite cities' ENDIF
You could also exclude the "= false/true" portion from these statements entirely, since the result is a true/false value. So, these statements could simply be written as:
IF isinlist([Favorite Cities],'Vancouver') THEN 'You selected that Vancouver is one of your favorite cities' ENDIF
The wildcard modifier function library has a number of useful functions that you can use in your conditional statements. Please review the library for additional functions. Hover your mouse pointer over each function to view a tooltip containing an explanation.
Syntax Guide
These are case sensitive and should always be written in uppercase
Operator | Description |
---|---|
IF | Open the Conditional Statement |
> |
Greater Than Operator |
< |
Less Than Operator |
= |
Equals Operator |
<> |
Does not Equal Operator |
AND |
Join one or more conditions in the IF or ELSEIF statement using the AND operator |
OR | Join one or more conditions in the IF or ELSEIF statement using the OR operator |
THEN | Always the last element after a condition |
ELSE | The final condition line in the statement, what follows is executed if there was not match to any condition above |
ELSEIF | Start of a new condition. This line must end with a 'THEN' statement |
ENDIF | Close the Statement. This must always be the final line of the condition |
0 Comments