Live Forms v8.0 is no longer supported. Please visit Live Forms Latest for our current Cloud Release. Earlier documentation is available too.
Working with Rules
Business rules are added by editing your form or workflow. Click the Rules icon in the form/flow designer toolbar to add new business rules or edit existing ones.
provides two ways to create business rules:
- Visual Rule Builder - visual wizards to help create your rule. The Visual Rule Builder provides access to the generated JavaScript in the Rule Validator for editing.
- Rule Validator - canvas to type in JavaScript with tools to help form/flow designers write and debug rules.
Create a new rule by clicking on the icon.
Each rule has two icons:
- Click the icon to choose the Visual Rule Builder or the Rule Validator canvas to add a new rule or edit an existing one.
- Your new rule is given a randomly generated name. Change the name and description to describe the rule function.
- Rules are enabled by default. They can be temporarily disabled by unchecking the Enabled checkbox.
- Click the Run Builder button to open the Visual Rule Builder (Click the link to find out more information about the wizard) or the Rule Code button (Click the Rule Code link for details about the Rule Validator) to enter the JavaScript directly.
- Click the icon to delete a rule. Confirm your choice in the dialog that pops up and the rule will be immediately removed. This is an irreversible process so make sure you do not need the rule before you delete it.
- Click the to test your rule without leaving the Rule Editor
- Click the View All link to see a readonly list of all the rules in your form/flow.
Refer to Rules Examples for many real world samples.
On this page:
Writing Rules / Syntax
A business rule is created as a piece of JavaScript code. The Rules Builder provides a wizard that generates the JavaScript for you or you can enter the code directly into the Rules Validator canvas. Either way, rules are saved and runable after you commit your form. In order to test a rule you must first commit your form. Then test it in use mode by clicking on the icon.
A rule is of the form:
if (condition)
{
true actions;
}
else
{
false actions;
}You can create more advanced rules primarily for the purpose of looping over repeating items. We will describe these later in the many rules examples below.
Some basic concepts of JavaScript:
Everything is case-sensitive. Ex: var color1 and var Color1 are two different variables.
Variables are loosely typed. Ex: var color = 'red'; and var num = 33 case the variable color to be a string type and num to be a numeric type.
End-of-line semicolons are optional. However we recommend you use semicolons to terminate lines as part of proper coding practice as this often prevents mistakes. Also the rules validator will flag missing semicolons as an issue. So do add them to your lines.
Comments. Code can be commented out using either // or /* */ syntax
Rules do not currently support the syntax:
switch statement
Rules support the following syntax with some limitations:
try-catch
Example: The value of the control named FN will get set to 'got exception' because the JavaScript variable named x is undefined in this rule.
if (form.load) {
try {
x.randomproperty = 'blah';
} catch (e) {
FN.value = 'got exception';
}
} However, catching an exception when a
if (form.load) {
try {
Color.value = "red";
} catch(e) {
msg1.value = "error caught: " + e;
}
}Strings vs Numbers
Because JavaScript is a loosely typed language you may run into occasions where you are trying to add field values and the rule performs string concatenation instead. There are several ways to designate math vs string. One simple way is by adding a *1 to the variable. id = id*1 + 1; will ensure that id equals the current value plus one rather than the current value with a 1 appended. Ex: If the current value was 4 and you didn't write id*1 the result may be "41" rather than 5.
You may also encounter a situation in a rule in which money controls perform a string concatenation rather than addition. To correct this:
Open the form with the rule in the Designer, change the money controls to text controls, and then save the form.
Open the form, change the text controls back to a money controls, and then save the form again.
See this topic about string and numeric conversion.
Writing Conditions
One of the most common conditions is a rule that executes as soon as the user enters a value in control. The test for this condition depends on if the field is a string type or a numeric type.
String Types: text, textarea, date, phone
if (name.value.length > 0) Numeric Types: money, quantity, number
if (name.value != null) or if (name.value > 0) are both common test conditions.
Many times the condition name.value.length > 0 can be dropped altogether and the rule can be simplified. This rule executes whenever a user enters a value into either the control named firstname or lastname because the firstname and lastname controls are on the right side of the assignment operator.
fullname.value = firstname.value + ' ' + lastname.value; Conditions testing for equality should use the === operator and not the ==. The latter will not pass the validator's strick syntax verification even though it may perform correctly at runtime. It is a good habit to always use ===.
if (Age.value === 13)Use caution when switching == to === as the latter removes the type coercion. For example, dropdown, radio and checkbox control values are text types. So you must quote values when performing comparison operations:
Ex: if (Building.value === 1) will evaluate to true. You must quote the 1 as in if (Building.value === '1') to make the one a text type.
Control Name
Rules usually need to reference form controls. You assign a control a name using the control's name property.
Names are case sensitive. If your control is named FirstName then you must write the rule as FirstName.value. firstname.value will not work.
Use English alphabet characters only when naming controls. For example, controls named with ó as in Póliza may cause issues when the control is used in a business rule and with submission data.
It is highly recommended that you avoid using JavaScript Reserved Keywords as control names. For Example, a section named New in your form will cause rule validation errors if explicitly referenced in a rule. Your rule may still work but the only way to fix the error in the rule validator is to change the name of the control. Click here for a list of the JavaScript Reserved Keywords to avoid.

