Writing Conditional Statements

logiforms supports an easy to use syntax for writing conditional statements using the standard IF / THEN / ELSE format. Below are the guidelines and some examples to get you started.  Conditional statements are always written in the Bind Editor.  

 

Important Formatting Guidelines

1. The value you are evaluating MUST be inside single quotes (ie. 'California')

2. The field name must always match a field name on your form (ie. [STATE]).

3. You must have the "THEN" keyword at the end of every line that starts with IF, or ELSEIF.

4. You do not need the "THEN" keyword after the final ELSE statement as in the example below.

5. The "ENDIF" keyword must be included at the end of the statement and it must be as shown here.

6. If you are evaluating a number (ie: IF [myfield] > 10) then you do not need to and should not use quotes around the number.

Examples

Example of an IF/THEN/ELSE statement:

This next example shows how to use the ELSE statement to run a calculation when the IF statement does not equal 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:

In this example, multiple statements are evaluated. The statement is executed 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

Wildcard modifier functions can be used in the condition statement to add additional evaluation options. For example, you can use the getYearsOld() modifier function around the date of birth field to calculate an age and then use it in an evaluation.

 

Assigning a WildCard Modifier Function

  1. In the Bind Editor, highlight the wildcard in the condition
  2. Click the functions button
  3. Select the WildCard Function to apply

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:

 

Checking TRUE/FALSE results from Modifier Functions

Many of the wildcard Modifier functions return a true or false value. These can be used in your conditional statements. Note, that when checking the result of a modifier function used on a condition row, the true/false value should NOT be in quotes.  

 

This example is correct:

IF isinlist([Favorite Cities],'Vancouver') = true THEN

   'You selected that Vancouver is one of your favorite cities'

ENDIF

While this example would fail due to the quotes used around the true/false result

IF isinlist([Favorite Cities],'Vancouver') = 'false' THEN

   'You selected that Vancouver is one of your favorite cities'

ENDIF

Note, that you could also exclude the "= false/true" portion from  these statements completly because 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. By rolling over the function a tooltip is provided with additional information on how the function might be used.

Syntax Guide

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