# Logic Page

Logic pages enable conditional branching, variable assignment, and basic mathematical and string operations directly within your Voice Site without having to rely on an external script to perform these functions. You can also specify the destination page.

Note: If you specify conditions, assignments, or transformations, you can copy and change the order (up or down). You can also merge multiple conditions into one condition.

## Conditions

Insert an IF statement into your Voice Site with a conditional branch. You can have as many conditions as you want, and use AND or OR with respect to those conditions. Within each branch, you can have unlimited Assignments and Transformations. The available conditions are equals, not equals, greater than, less than, greater than or equals, less than or equals, starts with, ends with, contains.

After specifying the conditions, specify a destination page if the conditions are met. If they are not met, the destination page is the one you set for the page.

### Rules for Conditions

Rule Description
Mixed Type Operation Casting Rule If one element is a list in the comparison the scalar is cast into a single element list.
Number Rules If a scalar operation occurs where both scalars are numeric, those scalars are treated as numbers for the purpose of mathematical comparisons. If a scalar is numeric in an operation and another is not, those scalars are treated as strings (for example, (abc) greater than (a) = true)).
String Rules If the scalars are evaluated as strings the java.compareTo function is used and that value is compared to 0 (for example, (AB) greater than (B) would look like "AB".compareTo("B") >0).
List Rules
• Equals: List A, and List B must be an exact copy to result to true.
• Not Equals: This only results in false if List A, and List B are equal.
• Starts With: Determines if a list A starts with the elements in List B in order.
• Ends With: Determines if list A ends with the elements in List B in order.
• Contains: Determines if List A, contains all the elements in List B.

The following cannot be used with Lists and will result in the logic page going to the error destination:

• Greater Than
• Less Than
• Greater than or Equals
• Less than or Equals

## Assignments

Assignments allow you to assign the value of a variable to the following:

• Constant—Enter a constant.
• Variable—Select another variable.
• Random—Select one of the following
• Number—Enter a range of numbers.
• Numeric—Enter the number of allowed digits in the numeric value.
• Alphabetic—Enter the number of allowed digits in the alphabetic value.
• Alphanumeric—Enter the number of allowed digits in the alphanumeric value.

You can also add conditions (as the graphic shows), additional assignments, and transformations to this page, by clicking the associated button.

After specifying the assignments, specify a destination page if the assignments are met. If they are not met, the destination page is the one you set for the page.

## Transformations

Transformations allow you to assign the value of a variable to a constant or to the value of another variable. You can perform the following mathematical and string operations on variables or constants: add, subtract, multiply, divide, append, remove, +space+, length, first, last, reverse, substring, and trim.

You can also add conditions, assignments, and additional transformations to this page, by clicking the associated button.

After specifying the transformations, specify a destination page if the transformations are met. If they are not met, the destination page is the one you set for the page.

### Date and Time Manipulation

You can use the Transformation function to add or subtract any interval of time to or from a date or time variable.

In the image above, the DateResult variable is assigned a value based on the following:

• Date1 - a variable (MM/DD/YYYY)
• add - the mathematical operation
• 30 - the value
• day - the time interval

In other words, in this example, you are asking the system to look at the Date1 variable and then add 30 days to it. It will then store the result of that calculation as a value of the DateResult variable.

### Rules for Assignment & Transformation

Rule Description
Mixed Type Operation Casting Rule If one element is a list in the transformation, the scalar is cast into a single element list, and the transformation is performed (except in the case of mathematical operations on numbers).
Result Casting Rules
1. If the result variable is of the same type as the operation result, the result variable is set to the operation results (no cast is required).
2. If the result variable is a list, and the operation performed results in a scalar, the result variable contains one element that is that scalar (for example, (a) becomes [a]).
3. If the result variable is a scalar, and the operation performed results in a list, the list is cast into scalar, by concatenating its elements (for example, [a,b,c] becomes (abc) except in the case of numbers). For numbers, if the result is a list, and the variable it's being stored into is a scalar, the values are summed (for example, [13,5,7] becomes (25)).
Number/Currency Rules
1. Currency values are treated as a number, but the result is always cast as a currency (for example, (\$5.00) multiply (5) becomes (\$25.00) and (\$5.00) multiply (\$5.00) also becomes (\$25.00)).
2. On the (add, subtract, multiply, divide) mathematical operations:
• If both numbers are scalar numbers - The operation behaves as the normal numeric mathematical operation.
• If one value is a Scalar Number and the other a List of Numbers - The operation is performed on each item of the list with the scalar number, and a modified list is the result (for example, [5,10,25,2] add (2) becomes [7,12,27,4]).
• If both values are list of numbers - Each element in the first list is operated on by the corresponding element in the second list, based on order. If the lists are not the same size, an error is thrown (for example, [5,6] multiply [2,3], 5 would be multiplied by 2, 6 multiplied by 3 yielding a list of [10,18]).
• If there are non-numbers involved an error will be thrown, now these operations will explicitly apply to numbers only. If you need to append strings you would use the append function.
Exceptions The following operations result in going to the error destination of a logic page:
1. Any mathematical transformation where one of the values is a string:
• String addition >> for example, (a) add (2), (c) add (d)
• String subtraction >> for example,(a) subtract (2), (c) subtract (d)
• String division >> for example, (1) divide (a), (Ben) divide (Young)
• String multiplication >> for example, (1) multiply (b), (Ben) multiply (Young)
2. Any mathematical operation on 2 Lists of non equal size (i.e. [5,6,7,9] add [2,3])
3. Any mathematical transformation on Lists, where 1 value is not a number (i.e. [5,7,9] add [5,6,A]).

#### How do the non-mathematical operators behave?

The following table describes non-mathematical operator behavior:

Operator Behavior
Append
• Lists: A list containing the elements from left to right is created [a,c] append [b,d] = [a,c,b,d] What if those list contain numbers such as: [1,2] append  = [1,2,5]
• Strings: (Ben) append (Young) = (BenYoung) The strings are concatenated
Remove
• Lists: All elements in the second list are removed from the first list to create a sublist. [a,c,d] remove [c,d] = [a] What if those list contain numbers such as: [1,2,5] remove  = [1,2]
• Strings: (BenYoung) remove (Young) = (Ben). (Benjamin) remove (Ben) = (jamin) (BenBenYoung) remove (Ben) = (Young). All instances of the left substring are removed from the right substring.
+space+
• Lists: An error is thrown if this operation is performed on a list.
• Strings: (Ben) +space+ (Young) = (Ben Young) The strings are concatenated with a space in between them.
Length
• Lists: The length of the list is returned [apple,bear,cat].length = (3)
• String: The length of the string is returned (Ben).length = (3)
First
• Lists: The first element of the list is returned [apple,bear,cat].first = (apple)
• String: The first character of the string is returned (Ben).first = (B)
Last
• Lists: The last element of the list is returned [apple,bear,cat].last = (cat)
• String: The last character of the string is returned (Ben).last = (n)
Reverse
• Lists: The list is reversed [apple,bear,cat].reverse = [cat,bear,apple]
• String: The character string is reversed (Ben).reverse = (neB)
Substring / Sublist
• Lists: The operation returns the sublist from the start position to end position inclusively. [apple,bear,cat].sublist(start:1,end:2) = [apple,bear] Note: The index of the first position is 1, not 0.
• String: The operation returns the substring from the start position to end position inclusively. (Ben Young).substring(start:3,end:5) = (n Y) Note: The index of the first position is 1, not 0.
Trim
• Lists: Each element of the list is trimmed of pre and post white-space [apple , bear , cat].trim = [apple,bear,cat]
• String: The string is trimmed of pre and post white-space (Ben Young ).trim = (Ben Young)

The system may encounter three exceptional situations that could trigger an error:

1. The query takes too long to run
2. The Data File has reached the maximum allowable size
3. There was an internal system error
• Error Destination—Configure which page in the IVR the call should be routed to in the event an error occurs.
• Email Debugging
• Mail Logs—Choose when to send email logs. You can chose either Never, On Error Only, or Always.
• Email Address—By default, this field displays the global debugging email address you specified in Site Properties. Here, you can change the debugging email address for this page only. If you do that, an icon will display next to the page name in Site Overview with a message stating that the debugging email address on this page differs from the global debugging email address.
• Debugging email addresses have the following character length limitations:
• Total length: ≤256 characters
• Local-part (text that precedes the @ symbol): ≤64 characters
• Domain (text that follows the @ symbol): ≤255 characters

Note: This is an option on the Data Page, Transaction Page, Logic Page, and SMS Page.