/
Rule Examples

frevvo v11.1 is no longer supported. Please visit the Documentation Directory for our current Cloud Release and other versions.

Rule Examples

Overview

This chapter contains numerous real-world samples of the custom dynamic behaviors you can add to your forms and workflows. Many of the business rules described below are easily created with the frevvo Visual Rule Builder by simply selecting appropriate functions or controls from your forms/workflows using a visual wizard. Rules can still be written with JavaScript in order to build any degree of complex, powerful business logic and integrate with your Web Services and frevvo connectors.


Navigating this Page

This page is divided into the following sections. To search the headings and content, type Ctrl-f and enter a keyword.

SectionSubsectionsExamples
Rule Events

Rule Examples#form.load | Rule Examples#form.unload | Rule Examples#form.activate

Rules by Function



Rule Examples#Calculations

Control Types for Calculations | Rule Examples#Addition | Rule Examples#Multiplication | Calculate a Subtotal | Calculate a Grand Total | Round a Number | String Concatenation

Show/Hide Rules

Show/Hide based on a Control Value | Show/Hide if another Control is Filled | OR Conditions | Multiple Conditional Statements (if-else if) | Show a Tab on a Workflow Step | Show/Hide Submit and Cancel Buttons | Show/Hide Approval Sections on Workflow Steps | Switch Form View in a Workflow

Control Property Rules 

Rule Examples#Printable | Enable/Disable Submit and Continue Buttons | Enable/Disable a Control | Set Valid/Invalid Property | Set Error Message | Set One or the Other Control to Required |  Required Field Status in Accessible Forms | Dynamic Label, Help or Hint | Expand/Collapse Section | Select Tab | Next Tab | Rule Examples#Pattern

Formatting Rules

Format Money Values to Display in a Message Control | Format Money in Text Controls | European Number Format | TextArea Max Length | Convert TextArea newline to HTML break | TextArea Wrap Long URL in PDF Snapshot |     Split Phone Number

Prefilling Rules

Tenants, Roles, and Users | Initialize Form with Current User Info | Populate Form with Any User's Info | Populate Dropdown with Users/Roles | Populate Dropdown with Roles Assigned to a User | List Users in a Role | List Users in Multiple Roles | List a User's Roles | Verify User | Verify Role | Unique and/or Sequential ID

Rule Examples#Signatures

Signature via Web Service | Set Signed Date | Enable Click to Sign for Anonymous User

Doc Action, ADA, Precondition-Related

Conditionally Send Email

Rules by Control TypeSelection Controls

Options | Set Options | Set Options to Control Values | Default Selection | Display Selected Option Label | Clear Selections | Randomize Options | Dynamic Options | Options from a Database | Combobox Options from a Webservice | Options from a Google Sheet | Synchronized Dropdowns | Find a Selected Options Index | Filter Dynamic Options | Triggers & Dynamic Options | Search a JSON String | Cascading Dropdowns | Dynamic Control Initialization with JSON

Comment Property Rules | Set Comment Field | Retrieve Comment Value | Set Max Length for Comment Field

Checkbox Control Checkbox Initialization | Display Selected Checkbox Labels | Checkbox isFilled Condition | Selected Checkbox Options in Conditions | Many Checkbox Comments | Set Options for a Checkbox to Values of Another Checkbox | Count the Options Selected | Repeating Checkboxes

T/F Boolean Control | T/F Value as Condition | Set a T/F Value | Clear a T/F Value


Date and Time Controls 

Working with Date and Time Rules

Set Dates and Times | Today's Date and Time | Date/Time Stamp | Create a Date, Time or DateTime Value | Set a Future Date | Set a Future Date Based on Five-Day Work Week | Get Day of Week from DateCalculate a Return Time | Set a Pay PeriodTime Zone Adjusted for Daylight Savings

Rule Examples#Duration | Rule Examples#Age | Stay Duration (Days) | Duration Including Start & End | Duration (Working Days) | Duration between Date/Time | Calculate Hours Apart | Calculate Time Between

Date Conditions Date No More Than x Days From Today | Date No More Than x Days Ago | Show Error Message if Date1 is On or Before Date2 | Display a Date in a Message Control

Checking a Date for Extra Digits | Copy Date, Time and DateTime Values


Rule Examples#Repeats 

Show/Hide Controls in a Repeat | Repeat itemAdded Condition | Collapse Prior Items When Item is Added | Dynamically Set Min and Max in a Repeat | Repeat Item Initialization | Repeat itemAdded by Init Doc | Repeat Item Increment


Rule Examples#Tables

Table Column and Cell Properties | Show/Hide a Column in a Table | Hide the Minus Icon on a Table Row | Dynamically Setting Min/Max in a Table | Populate Table Rows based on Query Results | Clear Values in a Table | Clickable Links in a Table | Set a Value Based on Table Rows | Count the Number of Items in a Table | Sort a Table by a Column Value


Upload Control

Display Uploaded Image | Dynamically Set Min/Max Properties | Upload Control Required/Optional | Count Uploaded Files | Display Uploaded File Names in a Dropdown | Rename an Uploaded File | Set Max Total Size for Submission


Message Control

Display Form Data | Display a PDF in a Message Control | Method 1: Host the PDF on your website | Method 2: Upload the PDF in frevvo's PDF Mapping tool | Display PDF with mapped fields | Embed a Video in a Message Control

Rules for Integration


Rule Examples#Geolocation | Use Google Maps API to Calculate Mileage | Add a Calendar Event LinkSearch Popup | LDAP Custom Attributes | REST Web Services

Rule Events

Whether you are using the Visual Rule Builder or editing Rule Code, it is helpful to understand some of the common events that you will use to trigger rules as they can affect the behavior of your forms/workflows. The following examples illustrate the use of form.load, form.unload, form.activate, and form.deactivate events. 

Refer to the When Do Rules Execute section for more information.

form.load

Rules can be used to initialize field values. This is a very useful feature and is often used to dynamically populate dropdown options from a database. Rules using form.load are triggered when a form first loads and when a workflow is loaded from a task list.

Rules using itemAdded only execute for repeat items added when the user clicks +, and for those added from an initial instance document (See Document URIs). It does '''not''' execute for those items that you have added to your form in the Form Designer. You can either add defaults directly via the form designer or add a 2nd rule to your form as follows.

These two rules together initialize the dropdown fields inside a repeat that is already in the form via the Form Designer, as well as those added each time a user clicks "+" on the repeat to add a new item & via initial documents. These controls are initialized based on a value set in another field.

Rule Code
//1st Rule - Default Items
if (form.load) 
{ 
    // The form contains two repeat items by default.
 
    if (department.value === 'Marketing') { 
        Managers[0].options = ['Joe', 'Mary', 'Stan', 'Cindy'];
        Managers[1].options = ['Joe', 'Mary', 'Stan', 'Cindy']; 
} 
    if (department.value === 'Sales') {
        Managers[0].options = ['Lou', 'George', 'Wendy']; 
        Managers[1].options = ['Lou', 'George', 'Wendy'];  
    } 
}
 
//2nd Rule - Items Added
if (Erepeat.itemAdded) 
{
    var index = Erepeat.itemIndex; // which item is this in the list  
    ES[index].value = 'Day'; // default the employee shift to day
 
    // Use options already selected in form.load rule 
    Managers[index].options = Managers[0].options; 
}

In the Rule Builder, designers can specify at the rule level whether or not a given rule is intended for initialization or not. Checking the Initialization Only checkbox on the wizards marks a rule as an initialization rule. If checked, the generated rule will be wrapped in an if (form.load) statement. The rest of the generated rule (conditions, actions, etc) will be contained within this if statement. The rule shown sets the field named name to "Paul" if the value of the Gender dropdown is "male" and the workflow is on the second step.

Rule Code
if (form.load) {
  if ((gender.value === 'male') && (frevvo.step.on('_8yjc0OSvEeafOKEJqSXZcw'))) {
    name.value = 'Paul';
  } else {
    name.value = null;
  }
}

 If this same rule is not marked for initialization, it will behave like an anytime rule which means that it will fire when the form loads as well as a control value change. The generated JavaScript will include:

var e = form.load;

form.unload

Rules including the form.unload event are not yet supported in the Visual Rules Builder and thus still requires some JavaScript. Rules can be used to finalize field values after the users clicks the form's submit button but prior to the Form and Doc Action execution. Rules using form.unload are triggered when the form user clicks the submit button and for workflows when the user clicks continue to go to the next activity or finish to complete the workflow.

One common example use is for an order form order number. You may only want to assign a unique sequential order number to each order submission. You could initialize the form's order number when the form loads using form.load. However, if someone starts filling in the order form but never submitted it you do not want to consume the next order number in sequence if it will never be used. Using form.unload you can assign the number after the submit button click but before the form data is submitted.

Here OrderNum is the name of invisible control.

Rule Code
/*member num */
var x;
 
if (form.unload) 
{ 
    eval('x=' + http.get('http://(your webhost)/json/getNextOrdernum'));  
    OrderNum.value = x.num;
}

If you have a rule in your form that changes any control(s) after clicking Submit, thereby making the form invalid, the form will no longer be submitted and the invalid form will redisplay. This change avoids creating an invalid xml for a successful submission.

This feature is implemented for forms only.

The form.deactivate event is identical to the form.unload event. Whenever a step gets deactivated in a screenflow or multi-user workflow, it is unloaded as well. form.deactivate was added for completeness. The rule in this example will also work if it was written using form.deactivate instead of form.activate.

form.activate

In a desktop browser, users can navigate back and forth between the steps of a frevvo screenflow or multi-user workflow using the Navigation toolbar. Previous and Next buttons are available on mobile devices for this functionality. Workflow designers should consider this navigation when writing business rules. Steps in a screenflow are read/write since they are all performed by the same user and editing is allowed.

form.load is only triggered when the step is loaded for the first time. This is not very efficient. form.activate triggers every time a read/write step is displayed. This makes form.activate and form.deactivate events that give designers a more reliable way to set properties for steps in a screenflow.

Let's take a look at a two step screenflow designed using Linked forms to illustrate these points. Step 1 has 2 text fields, Text 1 is visible and not required. Text 2 is initially not visible and not required. We added a rule in the Visual Rule Builder that sets Text2 to visible and required on Step 2. 

Rule List

Notice that by default the VRB creates the rule on the form.load event.

Rule Code Generated by Rule Builder
var event = form.load;
if (frevvo.step.on('_4neSkLpxEeu1dMbj8N29dg')) {
  Text2.visible = true;
  Text2.required = true;
} else {
  Text2.visible = false;
  Text2.required = false;
}


Let's see what events occur when Step 1 is loaded.

  • LOAD Step 1 – the form.load is triggered since step 1 is being run for the first time. Text 1 is visible and required and Text 2 is not visbile and not required
  • ACTIVATE Step 1 – activate triggers because the step is loaded for the first time.

The user clicks continue and the workflow navigates to Step 2. Note Step 1 is deactivated and unloaded and Step 2 is loaded and activated:

  • DEACTIVATE Step 1
  • UNLOAD Step 1
  • LOAD Step 2 – the workflow is on step 2 – the form.load triggers because step 2 is being loaded for the first time. Text 2 is now visible and required.
  • ACTIVATE Step 2 – this runs because step 2 is displayed.

The user navigates back to Step 1 without filling in Text 2. Note Step 2 is deactivated and unloaded and step 1 is activated.

  • DEACTIVATE Step 2
  • UNLOAD Step 2
  • ACTIVATE Step 1

form.load is not triggered, so Text 2 is not visible (due to initial property value) but it is still required because Step 1 did not LOAD again. When the user clicks Continue to move to Step 2 the screenflow does not move forward.