Live Forms v6.3 is no longer supported. Click here for information about upgrading to our latest GA Release.

Skip to end of metadata
Go to start of metadata

Rules are probably best described by using examples. This chapter contains numerous real world samples.

On this page:

Calculate a Total

You have a form with three controls and you have assigned them Names N1, N2 and T respectively. When the user enters a value in either N1 or N2 you want to set the value of T to the sum of N1 and N2. The rule would be written as

This rule will automatically fire whenever the user types something in N1 or N2 and will set the value of T appropriately. You can use any legal JavaScript operators in the expression such as subtraction or multiplication. However, it's important to ensure that the calculated value is valid with respect to the type of T. For example, if T was of type integer and the computed value of the expression was decimal (such as 1.5), then the rule would be attempting to set an invalid value in T. This is an error. The rule will set the value as requested, but will mark the field as invalid and take appropriate action such as disabling the submit button, displaying the control with a red background etc. Also, if controls are added to the form from the palette, it is important to ensure they have the correct type. For example, for a numeric calculation as described above, the controls should be of type Numeric (found in the palette).

Show/Hide Controls

Designers can write rules to show/hide controls in a form based on data contained in another control or in a workflow based on the step that is being performed. The rule sets/unsets the Visible property of the control based on the specified conditions. Here are some common examples: 

Show/Hide Billing Address

You have a form with two controls and you have assigned them Names B and S respectively. B is a checkbox with a single option - Yes. S is a section containing controls to collect a different billing address. If B is checked, the user wishes to enter a different billing address in S and you want to display S. You can write the rule using the if...else conditional statement shown in the example on the left or the shortened syntax shown on the right.


This rule will automatically fire whenever the user checks or unchecks B and will show/hide the billing address section S. Again, you could use any legal JavaScript expression to compute the visible property of S as long as it evaluates to a boolean true or false value. In this example, you would typically set the checkbox B to be initially unchecked and the section S to be initially hidden.

Show/Hide Message - Example 1

This form has a radio control named Facility and a second radio control named CompanyFacility. This rule makes a message control named Msg visible depending on the selected options. If Boston is selected for the Facility control OR New York is selected for the the CompanyFacility control, the hidden message control will display. The rule can be written using the if...else conditional statement shown in the example on the left or the shortened syntax shown on the right:

Show/Hide Message - Example 2

This rule makes the message control nickNameThankYou visible when the user enters a value into the nickName input text control. And then hides the message control if the user deletes the value in nickName. The rule can be written using the if...else conditional statement shown in the example on the left or the shortened syntax shown on the right:

Show/Hide/Print

This form has a radio control named DescribeInDetail and a section control named Details. Details is hidden by default and made visible if the user selects 'Yes'.

When the form is submitted we've configured Live Forms to send an email with the form PDF. We only want the Details section to appear on the PDF when the user selects 'Yes'. So we uncheck the printable property on the section control. This property will apply to the section and all controls inside the section. So we do not have to uncheck printable on the inner controls. Then we add this business rule. When the section is visible we also set it to be printable. When the section is hidden we also set it to be not printable. You can write the rule using the if...else conditional statement shown in the example on the left or the shortened syntax shown on the right:

Show/Hide Submit & Cancel

You have a form with multiple tabs. The main tab contains the form and the other tabs contain reference information users may need when completing the form. You only want the submit and cancel buttons visible when the user is in the main tab. This rule hides the submit and cancel buttons when the reference tabs are selected. The control name of the main tab is MainTab. Be sure to select the Main Tab in the designer then save the form. This ensures the Main Tab will be selected when the form loads and the rule will run.

You can write the rule using the if...else conditional statement shown in the example on the left or the shortened syntax shown on the right:

Show/Hide Section

Often section controls contain many inner controls. For example imagine a form that contains a person's medical history. One of the questions on the form asks if the patient uses a hearing aid. If they answer yes, then you want to collect more details on their hearing aid usage such as left ear, right ear, bilateral; hearing aid brand; etc. If they answer no then you want to hide all the questions specific to hearing aids. Also when the answer is yes you want to require them to answer all the hearing aid detailed questions.

Avoid using message controls, images & video controls inside a section that contains other controls that you may want to make invisible. Since these three control types always contains a value, they can cause a section, or other controls in a section, to become required, and this can disable the form's Submit button. If you must include these controls, place them outside the section. Another alternative is to write rules for the individual controls within a section to set them to visible/invisible or required/not required

Imagine this example form has a section named HearingAid. By default HearingAid visible is set to false in the form designer.

When they answer yes, you must set HearingAid.visible=true AND also each required field inside the section to field.required = true. If they then change the answer to no then another rule makes the HearingAid.visible=false AND all the field.required=false. If the HearingAid section contains many child controls this rule becomes very long and tedious to write

We can simplify this by using the required property for sections. In the designer default all controls that must be answered inside HearingAid to required. Default the HearingAid section to not required and not visible. Your rule can be much simpler. By setting HearingAid.required=false all the inner controls recursively also become required=false.

See the documentation for Data Sources and Schemas for details on implementing a Show/Hide rule with XSD controls.

Show/Hide Steps in Approval Workflows

It is a very common practice to design workflows using linked steps. When using this design pattern, all the steps in your flow are created as sections in the first step and you create a linked version of step 1 for the remaining steps. A business rule is then used to show/hide the appropriate sections when the flow advances to each step. Your rule should use the _data.getParameter('flow.activity.name') to specify the step.

Let's say you have a flow that has three steps:

  • Step 1 is the Expense Report which is filled in by the employee.
  • Step 2 is the Manager Approval - the employee's manager approves or rejects the Expense Report.
  • Step 3 - the flow is routed to the Task Lists of all employees with the Accounting role to complete the processing of the Expense Report.

Step 1 is the parent form while steps 2 and 3 are linked copies of step 1. The parent form has a Section named Manager Approval and a section named Accounting. The Visible property on both these sections is unchecked so they are hidden by default.  You want to hide the Manager Approval and Accounting sections for the first step, show the Manager Approval section when the second step is performed by a manager and show the Manager Approval and Accounting sections when the third step is performed by an Accounting department employee.

Step 1 is named Expense Report, Step 2 is named Manager Approval and step 3 is named Accounting in the flow designer to match the sections in the parent form. The Manager role has been assigned to step 2 and the Accounting role has been assigned to step 3.

Here is an example of a rule that shows the Expense report details when the form loads, (the Manager Approval and Accounting sections are hidden) on step1, makes the Manager Approval section visible in the second step of the flow when performed by a manager and shows the Manager Approval and Accounting sections on step 3 when it is performed by an accounting department employee.

Show/Hide Manager Approval on Step 2 and 3 of a flow

You have a flow and the first form has a Section for manager approval. The Section is hidden by default. Here is an example of a rule that makes the section visible in the second and third steps of the flow which are linked steps assigned to the manager and VP roles. 

Refer to the Flow Tutorial which explains the show/hide rules in Purchase Order workflow in detail.

Show/Hide a Tab on a Workflow Step

This rule is useful in a workflow where you want to make a tab named Review visible only for the workflow activity named Manager Review.

Enable/Disable Controls

Submit/Continue Button Disabled

A great feature of Live Forms is the fact that a form cannot be submitted or a flow cannot be continued to the next step until all required fields are field and all filled fields have valid data (eg. a date field must contain a valid date). If you are Live Forms v6.1.3 or versions previous to 6.1.3, the submit/continue button is disabled if the form/flow has invalid fields. Sometimes it might not be as obvious to the form/flow user why the form/flow will not submit or continue to the next step. Use this rule to notify the user if you are using versions 6.1.3 or earlier.

In this example, Submit is the name of the form's submit button or the flow's continue button and Message is the name of a message control. Add a message control just above your submit/continue button and enter a message such as "Your form cannot be submitted yet because all required fields are not filled or you filled a field with an invalid value. Please correct the issue.". When all fields are valid the Submit.enabled fires and will hide the message.

In v6.1.4, this behavior has been enhanced and this rule will not work. Refer to this topic to see how the enhanced feature works.

Enable/disable a question

You have a form with two controls and you have assigned them Names B and Q respectively. B is a checkbox with a single option - Yes. . If checked the user is a smoker and you wish to ask an additional question in Q. The rule would be written as

This rule will automatically fire whenever the user checks or unchecks B and will enable/disable the question in Q. Again, you could use any legal JavaScript expression to compute the enabled property of Q as long as it evaluates to a boolean true or false value.

In this example, you would typically set the checkbox B to be initially unchecked and the control Q to be initially disabled.

Compute Subtotals for Repeating Items

This rule is an example of working with repeating items. Let's say, you have a form with a repeating section representing an Item that the user may purchase. Each section has a Price (with Name P), a Quantity (Name Q) and a Subtotal (Name S). There are multiple items on the page and the number of items on any given page is unknown. The price field is filled in automatically. When the user enters a value in the quantity field for any item, you wish to compute the subtotal.

The rule would be written as:

This rule will automatically fire whenever the user enters a value in the quantity field for any item. It will compute the subtotal for each item, for which the quantity is greater than 0 and fill in the subtotal field for that item with the computed value. If a particular item does not have a quantity, the subtotal is not computed.

Compute an Invoice Total

Consider the same form as the example above. Let's say you have a control named Total with Name T. You want to set the value of Total to be the total invoice price, which is the sum of all the computed subtotals above. This rule would be written as:

This rule will fire whenever a subtotal is updated, for example, when it is updated via the rule above. It will add the values of all the subtotals to arrive at an invoice total. Note that you must use a temporary variable to compute the total. If you write the rule as:

it will not work correctly. This is due to internal limitations in the way rules are evaluated. You can read more about that here

Note that this rule is working with controls inside a repeat control. To handle the case of a item being deleted from the repeat you need the following addition assuming that the repeat control is named ExpenseRepeat. Table controls are repeats with a different layout. Thus the same applies to the table controls. If your table is named Expense then the repeat is automatically named ExpenseRepeat. In general the table repeat is named <TableName>Repeat.

Formatting money values to display in a Message Control

Let's say you have calculated a sum in a Number control in your form and you want to display it in a Message control and format it as a money value with commas and decimal places.  You will need a Number control named Num and a message control named Message in your form. This rule will display the number entered in the number control with commas. If the user enters 5600.44 in the number field then the result in the message control would look like this:"5,600.44".

Textarea Max Length

In html there is no way to set a maxLength on a textarea control. This is why the textarea control does not have a maxlength property like the text control does. It is possible to do this via a business rule. This example form has a textarea control named 'Desc' where the user can enter up to a 500 character description. On this control we also set the ErrorMsg property to the string 'You must limit your description to 500 characters'. This message is automatically displayed when the description control is set to invalid by the following business rule.

You can even customize the error message by adding this line to your rule. Now the error message will tell the user how many characters they are over the maximum allowed.

Required Field Status in Accessible Forms

You can build forms/flows In Live Forms that meet Section 508 and WCAG 2.0 accessibility standards. Accessible forms/flows can assist users with visual and motor impairments. When the Accessible property is enabled for a form/flow, the error, "You can't leave this empty <control name>"  displays, if users move ahead from a required field without filling it. The status property for the empty control becomes invalid and sets the error message. Normally, the status property can be used in a business rule. For example, let's say a form has a text control named 't', and a message control named "m". If you write a rule to update the message field (control named m) with the STATUS of the required/invalid control (control named t), as shown below, it will not work because the "You can't leave this empty" message for a required control is not treated as it's status.

If the rule is written this way, it will fill the message control with the errmsg from the invalid text control.

Textarea newline vs break

Users typically enter multi-line text into textarea controls. If you want to display that text in an html context, for example on a web page or in an html formatted email or in your form's Form Action display message you will need to replace newlines with html breaks. This caused by the fact that line breaks entered into a web form textarea are represented by a single newline character \n while line breaks in an html context are represented by the html break characters.

Our example has a textarea control named Description and a hidden control named DF. The user types into the visible control named Description and a business rules converts the newline characters \n into html breaks.

Selection Controls

Dropdowns, Checkboxes, Radio and T/F controls are selection controls. Rule examples for these controls are shown below:

Dropdown Options

This example automatically sets the option selected in one dropdown based on the option selected in another. This is often useful when you have a form with choices that were dynamically populated. For example, imagine product choices which are descriptive text. When the user selects a product, your form needs to perform an action based on a product ID rather than the descriptive product text. A nice way to do this is to have the rule that dynamically populates the product choices dropdown also populate a product ID dropdown which remains an invisible control in the form. The product choices dropdown control was named Products and the product ID dropdown control was named PID

The 1st rule "Load Products" populates both the visible and hidden dropdowns with options from a database.

Finding a Selected Options Index

The 2nd rule Select Product ID keeps the hidden PID dropdown synchronized with the visible Products dropdown.

Rules using hidden dropdowns to keep descriptive option labels visible to the user while keeping cryptic database values hidden are often no longer necessary. Dropdown options have values distinct from the human visible option labels. The above can now be achieved with a single simpler rule:

Here is another rule that dynamically populates both the product choices and product ID dropdowns. This rule calls a REST Service which returns an object rather than the resultset returned by the database connector as shown above. See the section on dynamic content for more details.

Synchronized Selects

The Product Search example above is often used in conjunction with a hidden select control. Imagine that your database table contains a list of products. Each product has product description also a unique product ID. The user needs to select a product from a dropdown on your form. You want to populate the dropdown with the product descriptions. The users do not need to see or know the product IDs but you need to use the ID as the key into the database for other selects. To do this add another hidden dropdown to the form and populate it with the IDs. This example has a visible dropdown name Products and an invisible dropdown named PID. See the rule above that populates these dropdowns dynamically from the database.

This rule below keeps the PID selected option in sync with the selected Product.

Clearing Dropdown Options

This sample resets a dropdown option to the automatically added blank option. For dropdowns added from palette controls and from schema, Live Forms automatically adds a blank option so the dropdown initially shows no choice by default. To reset the dropdown, set the dropdown control's value to null not the empty string. The empty string will not work since the empty string is not a valid option. This form resets the dropdown named size whenever the value of the product option changes.

Default Option

When your options are set dynamically as shown below in a business rule, you cannot set a default in on the form designer. You need to set the default in the rule. If your options have <value>=<label> where value is different from label, make sure you set the <control>.value to <value> not <label> and not <value>=<label>

Populating Dropdown Options from a Google Sheet

Dropdown control options can be dynamically populated from a Google Sheet using a business rule. Here is an example of a rule that populates a dropdown control named Colors with color options from a Google Sheet.

  • Create a Google Sheet with a column named Colors containing a list of colors.

     
     

  • Create a Form with a control called Colors.

  • Use this rule to populate the dropdown options with the colors Red, Blue, Green and Orange. Note this rule uses http headers to provide authentication information and passes the Google sheet and worksheet names as query parameters. This is the recommended approach.

  • Replace <Google User ID>  and <Google Account access token> with your information in the user and password  headers. 

  • Change ssname= and wsname= to reflect the names of your Google sheet and worksheet.

 

Refer to this documentation for more information about Live Forms and the Google Connector.

Checkbox Options - Assigning Color to Checkbox Choices

Checkbox controls are different from all other Live Forms palette controls in that they are multi-select. Therefore the way to write rules with checkbox controls are in many ways similar to rules with repeat controls. This rule has a checkbox controls with name colorPalette with the options: purple, green, blue, yellow, orange. The form also contains a text control with name colorChoice. This rule assigns colorChoice the choices selected from colorPalette.

Notice that similar to repeat controls, due to an internal evaluation limitation, you must collect the choices in a variable inside the for loop. And then assign that control Name.value to that variable outside the for loop.

This rule is another example showing how checkbox controls are array types.

Checkbox Options - Making a Control Visible/Invisible Based on Checkbox Choices

This rule makes visible/invisible a control based on which checkbox options a user selects. This form contains a multi select checkbox named Structures. If the user selects the option "Detached Garage" or "House", we want to make visible a text field named Details.

Again since a checkbox is multi select, it is handled as an array. The array will contain all selected (checked) options.

It is important to note that when a checkbox is added to the form from the palette and its options are multiple words containing spaces, the option array has converted each space character to the '_' character. We must make the comparison as shown below. Checkbox controls from schema do not have space replaced with '_'.

Note that when we hide Details we also clear its value. This is because the user may have selected one of the Structures checkboxes that made Details visible AND entered a value into Details. And then they may have changed their minds and uncheck the option that caused Details to become visible. If you don't want the value entered into Details to be in your form submission, clear the value when hiding it.

Many Checkbox Comments

This rule makes an associated comment input control visible and required when a checkbox is checked. The for loop determines which checkboxes are checked and sets an appropriately named variable to true. Depending on the value of checkbox the associated input control will be made visible and required via the if/else and will be hidden and not-required when it is un-checked again. This is a very common rule design pattern.

This form uses the Live Forms Compact layout to align the comment input controls with the checkbox options. Download a working sample here.

Checkbox Initialization

Since checkbox options are multi-select, in order to select multiple options via a rule you must use this syntax. The correct way to initialize the checkbox control value is to collect all required options in an array and then assign that array as the value of your checkbox control.  In this example CB is the name of a checkbox controls with the following options: red, green, blue. This rule selects all of the options.

To clear all checked options in the control named CB:

Displaying Selected Checkbox Labels

In this example, the rule displays the labels of the checkboxes the user selects.

Retrieving or Setting the Comment Property for  Selection Controls

Dropdowns, Checkboxes and Radio controls have the capability to display a Comment field if the user selects the last option. It is most often used as an Other - please specify" option. In the Forms designer, check the Comment checkbox in the Properties panel and provide a # of rows for the comment area. If the user selects this option, a comment box will appear below asking the user to provide details.

Business rules can be written to retrieve/set the value of the Comment field using the commentValue property. Note that the initial value of the commentValue is null. Your rules may have to be coded to check for that.

This simple rule copies the value in the comment field of a dropdown control named Supervisor to a text field named. The rule will run only if the value in the comment field is not null.

Review this special syntax to reference comment fields in templates.

T/F Boolean

T/F controls are simplified checkbox controls with only a single visible option. This rule makes the control named "s" visible if the T/F control named "agree" is checked and invisible if the T/F control named "agree" is unchecked.

To set the checkmark on a T/F control:

To clear a checkmark from a T/F control you must set the value to null and ensure that the control is not required.

Repeating Checkboxes

Checkboxes inside repeat controls must be treated as an array (each checkbox control's values) of checkbox option values which is inside another array (the repeating checkbox control itself). This form example has a repeating section containing two controls -- Message which is a text control and AreYouAttending which is a checkbox control with a single option 'yes'. To access the selected options the syntax is:

AreYouAttending[i].value[0] === 'yes'

String Concatenation

Message controls can be used in business rules to create summary information on your form from values entered into earlier form fields. This rule uses javascript variables to concatenate form field values, text strings and html to format a nice summary page:

Note when using field values from repeat controls you must use a javascript var and assign the concatenation to the var and then the var to the Live Forms message control value. For example imagine you have a message control named Summary and a repeat control named Account:

Dynamic Labels, Help, Hints

You can set the value of control labels, help and hint dynamically in a rule. For example imagine you do not know the label, help or hint at design time but would rather set it dynamically when a user opens your form.

In the above example the label, help and hint is still hard-coded. It's just being set from the rule rather than in the form designer controls' properties. To make this more useful you can initialize these properties from _data parameters:

Since _data.getParameter enables access to values passed to the form that are not bound to actual controls this is often a very useful pattern.

Select Tab

This rule makes a specific tab the selected tab based on the choice of a radio control. The radio is named SelectTab and has three options: person, auto, home. The tabs are named personTab, autoTab and homeTab. Tabs also can be selected based on trigger controls or other input controls using the same method show here. 

Next Tab

This form contains a trigger control at the bottom of each tab labeled "Next". When "Next" is clicked the trigger rule executes and makes the next tab the selected tab. This assists the user in navigating through the form. The Tabs are named T1, T2, T3, T4. The trigger controls are named C1, C2, C3

Expand/Collapse Section

This form has three sections. The first section is expanded and the 2nd and 3rd are collapsed. When the user files in the 1st section they click a "Next" trigger control which causes that section to collapse and the next section to expand. The trigger controls are named next1 and next2. And the sections are named: step1, step2, step3. 

Security Subject Information

You can use a form.load rule to pre-populate fields in your form with information about the currently logged in user. For example, if you have controls in your form named Id, FirstName, LastName, Email, Roles and Manager the following rule will prefill those fields as indicated below.

Multiple Choice

This rule makes the appropriate input text controls visible depending on the choice a user makes in a radio option controls searchChoice.

Dynamic Options

Selection controls' (radios, checkboxes, dropdowns, T/F) options can be set dynamically via rules rather than statically via the control's options property. However if the control comes from an XSD schema data source rather than one of the standard palette controls, then the designer must take care to not set the options to something outside of what is valid for that schema element. For example if your XSD has a string enumeration and list valid options as 'red', 'green', and 'blue', then you should not use a rule to dynamically set the options to 'small', 'medium', 'large'. If you do then then your form will not work correctly in use mode. If a user selects the option 'small' they will get a validation error on the form. This is because 'small' is not one of the options allowed by your underlying XSD schema.

Triggers & Dynamic Options

This rule is executed when the user clicks the trigger controls with Name ''search''. It then dynamically sets options on a dropdown list control with Name coffeeShopList.

Now replace the hard coded list of coffee shops with a rule that invokes an http.get. This must return an X-JSON header which contains a JSON object. The object is evaluated and assigned to the variable x. In this case the JSON object contains an options field of type array. See the section on dynamic content for more details.

Triggers do not work in repeating items.

Value Change & Dynamic Options

This rule dynamically sets the options in a dropdown list based on the value selected in another form field. This form contains three fields named Products, Series and Model. The series options are set dynamically based on the product selection. Also when a new product is selected we enable the series dropdown and both clear and disable the model dropdown. This form contains other rules which set the models based on the selected series. 

Dynamic Control Initialization using JSON

This rule handles the case of initializing multiple control values based on the selection of a dropdown control. It handles this case better than using a long if/else construct by using a JSON string. First add options to the dropdown named SalesRep in the format <value>=<label> where <value> will be used as an index key into a JSON array of details about each person.

Then write a rule that first sets up a javascript JSON syntax array with the contact information for each person. The rules then uses the dropdown value to index into the contactInfo array to set the details for the selected person into four other form controls.

Try this simple Clinic Location form which uses this approach to initialize its controls.

Signatures

The following examples demonstrate rules working with wet and digital signatures.

Digital Signature

This form uses a rule to pass a username and password to a LDAP Active Directory authentication service. If authentication fails the form makes an error message control visible. If authentication succeeds the form disables the username form field and replaces the password field with a date field set to the current date. The form contains a trigger control named sign, username and password fields named u and p respectively, a date field named d and a message field named m.

The authService is an example HTTP servlet that returns a JSON response.

Here's another example form that requires a doctor's signature. This shows how the form works in use mode. The first image contains a dropdown to select one of the doctor's authorized to sign the form and a text control where they enter their PIN code.

This image shows the case where the doctor entered an invalid PIN and the error message becomes visible.

This image shows the case of a valid PIN. Today's date is entered into the date control via the rule and made visible and disabled from edit. The username dropdown is disabled and the PIN and Sign controls are hidden.

Wet Signature

This example sets a date controls to today's date as soon as the user signs the form. The wet signature control is named EmployeeSignature and the date control is named EmployeeSignDate.

Calculate Net Worth

This form contains two rules. One is adding values entered into a column of assets and a column of liabilities and calculating netWorth. The 2nd rule is checking the value of netWorth and displaying an error message and marking netWorth invalid if liabilities exceed assets since the form designer does not want the form to be submitted in that state.

When a rule sets <control>.invalid the control background turns red and the submit button grays out just as if the user had entered an invalid value into a phone control. Live Forms treats it exactly the same way. This is a good way to dynamically control your form's valid state.

Dates and Times

Working with dates and times is very common in most forms. The samples below show you how to create the most common business logic with dates and times. 

Live Forms dates can be set in the user's local timezone by using the built-in date, time and date/time methods such as frevvo.currentDateTime(). See Built-in Methods for a complete method list. If you use the base javascript date object you will get UTC timezone.

Many of the samples below use the javascript Date() object. Since business rules run on the form server these dates will be in the timezone where the form server was installed. There are techniques below to convert to different timezones as you need.

The Date/Time control uses a "T" to separate the date and time when initializing from a business rule. For example, the syntax shown below will initialize a Date/Time control named DtTm to May 15, 2012 at 4:20 am.

Date controls will successfully initialize via a rule or an xml document when the data provided has a single digit for the month and/or the day. The rule below can be used to initialize a form with a date and date/time control. Notice the Date.Value and Date+Time.value rule identifiers have a single digit for the month.  

The Date/Time control will display an "Invalid Value" error if single digits for the month and/or day are used .

 Change the Date_Time.value = "2011-1-23T20:20:20"; to Date_Time.value = "2011-01-23T20:20:20"; in the rule or the xml document for successful initialization.

Rules initializing time and date/time controls will not work in a form.load rule unless you specify a timezone on the form's Url via the _formTz Url parameter. This is because the form server needs to know the timezone in which to return the date and time. If you do not specify a _formTz the methods will return null and the control values will remain blank. The timezone strings can be found here. For example, to specify Eastern time: &_formTz=America/NewYork. This URL parameter is not needed if your form/flow only contains Date controls.

Age

This example form automatically determines today's date and then calculates the person's age in the control named 'Age' when they enter their birth date into the control named 'BirthDate'.

Duration

This form initializes the hospital discharge date using a rule, and when the user enters the admission date a 2nd rule calculates the number of days the patient stayed in the hospital.

Duration (between Date/Time)

Here is a rule example to calculate the time difference between two Date/Time values in hours:minutes format :

Today's Date and Time

Use Live Forms' built-in date and time methods to set your date, time, and date/time controls to the current date and time in the user's local timezone.

The currentTime(), currentDate() and currentDateTime() will not work in a form.load rule unless you specify a timezone on the form's Url via the _formTz Url parameter. This is because the form server needs to know the timezone in which to return the date and time. If you do not specify a formTz the methods will return null and the control values will remain blank. For example &formTz=America/New_York will set the control values to the current date and time in the eastern timezone.

Date/Time Stamp

This rule sets a control named Signature to the value of a control named Name plus a date/time stamp. Note that it is better to use the Live Forms built-in date and time methods if you want to set the date to the user's local timezone. The following method will set the date to the form server's timezone.

Invalid if Before Today

This rule makes the date control invalid if the date entered isn't before today's date.

Use frevvo.currentDate() rather than the javascript new Date() since the latter gets today's date in the Live Forms server's timezone while the frevvo currentDate() correctly gets today's date in the user's timezone.

Date no more then 14 days from Today

This rule checks that the date entered into a control named AppointmentDate is no more than 14 days greater than today's date.

Date no more then 30 days ago

This rule checks that the date entered into a control named EventStartDate is not more then 30 days ago.

Add Years, Months or Days to a Date

Here is a rule that will add 3 years to a given date.  For example, to calculate the expiration date of a three year contract by adding three years to the starting date, your form could have two date controls, one used to enter the starting date and the other to show the contract expiration date. This rule will take the date from the StartingDate field, add 3 years to it and populate the result in a field named ExpirationDate.

This rule adds 1 month to the Start Date:

This rule adds 11 days to the Start Date:

These functions can be used with Date and Date/Time controls.

Setting a Future Date

You can write a rule using the addToDate method to calculate a future date. The example code executes when the form loads. It uses the DateUtil.today() method to populate the control named D1 with the current date. This method returns today's date in the format 'yyyy-mm-dd' instead of 'mm-dd-yyyy', making it compatible with Live Forms utility methods such as addToDate(). The rule then

  • adds one month to the current date to populate the control named D2.
  • adds one day to the current date to populate the control named D3.
  • adds one year to the current date to populate the control named D3.

Calculate a Date based on a five day work week

You may want to calculate a date in a workflow based on a five day work week. This is a common business scenario and may be helpful if you are using the Live Forms Escalations feature. It is not possible to select calendar or working days for the Days interval of the Escalation feature at this time but this enhancement is planned for a future release. As a work-around, you can calculate X number of working days from the current date, and set that date in a Date control on your form. Then while configuring escalations, use the ‘Complete By’ condition and select the Date control.

Here is the business function/rule that will add 3 working days to the current date to give you the escalation date. Copy/paste the entire rule including the function in the Rule Editor. Substitute the name of your date control for <your date control>:

Central Timezone adjusted for Daylight Savings

This rule adjust today's date in UTC timezone to Central timezone and adjust for daylight savings time. This additional conversion is most commonly needed for  Online users as the javascript Date() and Live Forms' DateUtil.today() both return today's date in UTC timezone.

Hours >= 4 and <= 6 Apart

This rule makes sure the end time is at least 4 hours great then the start time but no more then 6 hours later then the start time. Also start time must be on or after 1:00. The times must be entered in military units. TS is the name of the Time Start control and TE is the name of the Time End control.

  • Use Text controls for the start and end times
  • Use this pattern in the control to ensure valid military times 1:00 or greater: ([1-9]|1[0-9]|2[0-4]):([0-5][0-9])

Calculate a Return Time

You can use a business rule to add a specified time interval to a value entered in one field and display the updated value in a different field. For Example, Let's say you have a Transportation Request where the user enters the start time of the trip into a control named LeaveTime. You want to automatically calculate the Return Time as 7 hours later and display it in a field named ReturnTime. Here is an example of a rule that will add 7 hours to the time entered.

Be sure to specify your controls as Time controls and change the control names to yours if they are different than shown in the example. You can change the number of hours added by modifying the value in the hour += 7 line in the rule to match your requirements.

Use this example only when you want to add whole number hours. Adding a decimal value for the time interval (such as 7.5) will not work.

Displaying Dates in Message Controls

Irrespective of your date control's Date Format, the Live Forms server stores that value in a connical yyyy-dd-mm format. Thus the Date Format affects only the format the user sees while using the form and not the actual stored value. The connical format is also what you will see in your form's submission XML. When you want to use a date control's value in a message control you will need to convert the connical date format to your desired display format. This rule writes the date control named datefield into a message control named Msg using the format dd/mm/yyyy.

Checking a Date for Extra Digits

This rule uses the valid property to verify that the entered date does contain extra digits. For example, if a user enters a date with a 6 digit year (1/2/201717) into a control named StartDate, the customized error message displays.

Times

The date control can be set to either just a date, just a time, or a combined date/time. Here are several examples of initializing a time control named Tm;

Tenants, Roles, Users

Live Forms have several built-in methods that enable you to access information about your current tenant such as a list of users and roles. See built-in methods for the complete list. Some of these methods return a boolean true/false value. Others return a JSON string that is automatically converted to a JavaScript object. There is no longer a need to include an eval method to handle the conversion when using these functions.

Here are some samples of how to use these methods.

Populate Form Fields with User Details

In this example, a user id is entered into the Enter User Id field. This field is a text control in the form named UserId. The rule uses the frevvo.userDetails(String userId) function to pull the user details (Id, First Name, Last Name, Full Name, Email Address and the Id of the user's manager about the user name entered into this field. Fields in the form named ld, FirstName, LastName, FullName, Email and Manager Id are populated with the results.

Populate Dropdowns with all Users/Roles in the Current Tenant

This rule populates the following controls when the form loads:

  • text controls with the name of the current tenant and the logged in user
  • a dropdown named AllUsers with a list of all users in the current tenant
  • a dropdown named AllRoles with a list of all roles in the current tenant

Leave the default options for the dropdown controls in the designer.

List All Users with a Specified Role

A common requirement is to filter the list of users in a tenant to display only users that have a specified role. The frevvo.userIds( ) and frevvo.roles( ) functions can be used in a rule to accomplish this.

One approach is to populate a radio control with all the roles in your tenant, allow the user to choose a role and then display the results in a dropdown. Another approach is to use an invisible text field where you hardcode the rolename. Remember that Live Forms role names are case sensitive.

Let's say you want to display a list of users that have the Manager role in a dropdown named Role. The user sees only the users that are assigned the Manager role instead of the entire list of users in the tenant. Once a user is selected from the filtered list you can display the details about that user.

Here is an example of a rule that filters the list of users to only those that are assigned the Manager role and populates the options of a dropdown control with the results. The frevvo.userDetails(String userId) function is used to retrieve the details about the selected user (Jim). The results are displayed in a formatted Message Control named m. The form has a text field named Role with an initial value of "Manager".  This field is referenced in the rule to supply the role name,

List All Users with Specified Roles

You can also select more than one role from your tenant list and use a business rule to display a filtered list of users who are assigned any of the selected roles. This business rule populates the options for a checkbox named Roles with the list of all users in the tenant. Selecting more than one role from the list populates a dropdown  named UserswithSelectedRoles with the filtered list of users assigned those roles. Details for the selected user are displayed in a formatted Message Control named m.

Verify User

This rule executes when the user enters a value into the Username text field. It uses the built-in isUniqueUserId() method that returns false if the user already exists. If the user already exists this rule then sets the value of a message control, makes that message control visible on the form and sets the Username valid property to false so that Username field displays as invalid to guide the user to make a correction. See the section on dynamic content for more details.

Verify Role

This rule executes if there is a value in a field named role. It uses the built-in isUniqueRoleId() method that returns false if the role already exists. If the role already exists, this rule displays the message "The role (rolename) already exists in the tenant (tenant name)." to notify the user.

Repeats

Repeat Item Added

This rule executes when a new item is added to a repeat. Imagine your form contains a repeating section named Employee with name Erepeat. NOTE: that the name Erepeat is set on the Repeat control and not on the Section control. The Employee section control contains many controls such as Name, Phone, etc.. and a dropdown control labeled Manager and named M. It also contains a radio control labeled Employee Shift named ES whose options have been set to 'Day' and 'Evening'.

Live Forms will execute this rule each time a user clicks "+" on the repeat to add a new item. Here we want to default the Employee Shift ES to the value 'Day', and populate the Manager dropdown dynamically with values from the Live Forms Database Connector.

Usually your form will have a form.load rule to initialize dropdown options for the 1st repeat item visible on your form by default.

Now when a new item gets added when a user clicks the "+" icon we can save the overhead of going back to the database to retrieve dynamic options.

Tables are repeats. So the same rule can be written for a table control. The name of a table's repeat is always <TableName>Repeat. For example if you name your table Children. Then the repeat is named ChildrenRepeat.

Repeat Item Added - Collapse Other Items

This rule executes when a new item is added to a repeat. This form contains a repeating section with a templatized label. It is nice to collapse the other items when adding a new item to keep the repeat list small and grid-like. Medrepeat is the name of the repeat control. Medication is the name of the section control inside the repeat.

Dynamically Setting Min/Max in a Repeat

Imagine an airline reservation form where the number of traveler information sections displayed or the number of rows in a table is based on the number of airline tickets purchased. There is a field in the form for the number of tickets named count and a repeat with a section including controls to collect information about each traveler. You can leave the default values for the Min/Max properties of the Section in the Forms designer or set them to any values provided the min value < max value and the max value  > min value.


This is an example of a business rule that displays the number of sections based on the number of purchased airline tickets. 

This example rule has the following components:

  1. The first part of your rule should retrieve the results set (this part of the rule is not shown here). In this example, the user enters a number in the Number of Travelers field in the form.
  2. The itemAdded statement is needed to determine if you are adding more sections. The first time the rule runs, this statement will evaluate as false and run the else statement
  3. Evaluate if the number of sections needed is greater than the number of existing sections. If true, set the maxoccurs first because the table needs to increase.
  4. If the number of sections needed is less than the number of existing sections then set the minoccurs first.
  5. The rule will loop through the existing sections and set the values in the TravelNo field. If there are still additional sections to be added after the rule has looped through the existing sections, the itemAdded lines will run.

Entering "5" as the number of travelers, sets the minOccurs and maxOccurs to 5 and shows 5 information sections.

This rule sets the Min/Max properties to he same values so the  plus and  minus icons are not visible. This prevents users from adding repeating items.

Repeat Item Initialization

The rule above was one example of initializing a newly added repeating control with a default list of options. This same concept is useful if you want to initialize a repeating control's value. When you add a repeat to your form in the Form Designer you can set a default value in any of those repeating controls visible in the designer. However when the user clicks "+" while using the form to add an additional item the default entered in the Form Designer is not automatically used in this new item. In order to accomplish this you can add a simple rule as follows:

This rule initializes the value of one of the fields in the repeat to a default of '0'. RepeatTrack is the name of the repeat control containing the input control named albumOnly. This rule will execute each time a new RepeatTrack item is added when the user clicks "+".

ItemAdded and itemIndex are properties of the Repeat control.

Again, to initialize repeat items already on your form in the Form Designer by default, either enter your initial default values directly into the in the Form Designer or add this rule.

This rule takes into account a repeat where min > 1. If min is 0 or 1, you can simplify this further by removing the for loop and simply have albumOnly[0].value = 0 inside the if (form.load).

Repeat ItemAdded by Init Doc

ItemAdded also executes when Live Forms adds items found in an init doc. You may want to only initialize items added when the user clicks "+" on the form. And not those added from an initial document. This form contains a Mailing Label that repeats. Each label needs a unique ID assigned. However once the form is submitted the assigned IDs are saved in the database via the form's Doc URI. When the form loads it adds items automatically from rows in the database. They already have assigned Ids. We only need to assign new Ids in the sequence when the user manually adds a new Mailing Label by clicking the "+" button on the form. MLrepeat is the name of the Mailing Label repeat. MLmid is the name of the ID field in the repeat.

Repeat Item Increment

You can easily auto populate incremental items numbers in repeats using a business rule. In this example Erepeat is the name of the repeat control and Item is the name of the item control inside the repeat. You also need to set 1 as the default value of first repeating Item control directly into your form field via the form designer as shown here.


Tables

Tables are identical to repeat controls when referenced in business rules. Tables are a grid layout of repeating items. All the rule examples in this chapter that discuss repeats apply also to tables. The one important note is that you cannot explicitly name the repeat control inside your table. The repeat control inside a table is automatically named as <TableName>Repeat. For example a table named Expense automatically has a repeat named ExpenseRepeat. The rule ExpenseRepeat.itemAdded and ExpenseRepeat.itemIndex references an item added to your table and that item's index respectively.

You can change a table control to a repeat control via the Control Type or Display As properties, depending on whether the table was dragged and dropped from the palette or added from schema. When you change a table to a repeat or vice versa and there are referencing rules, it is recommended that you check the rules to ensure you have the correct syntax.

Table Column and Cell Properties

The setting of properties on table cells and columns from rules is really at the "cell" level in that you are operating on a javascript array. For some properties, setting the property on any of the indices affects the whole column, while for others it only affects the individual cell. 

  • enabled (also available at individual cell)
  • printable (also available at individual cell)
  • required (also available at individual cell)
  • visible (also available at individual cell)

Enabled, printable, required, status, valid are cell level only and do not affect the column as a whole when used in a business rule.

Each column in a table has a label, help and hint property. These properties work at the column level and can be set dynamically with a rule. Here is an example: 

Show/Hide a Column in a Table

The Visible property is available on the column level and can be used in a rule to make the whole column visible/invisible. Checking/unchecking this property now only alters the visible property on the column as a whole and therefore the whole column can be hidden or shown in use mode.

For example, let's say you have a table with 3 columns in a two step workflow. You want all three columns to display for step 1 of the flow. When the flow navigates to step 2, you do not want the one of the columns, let's say the Id column, to display. In the designer, the visible property is checked on the Id column property panel.

Here is the rule that hides the Id column on step 2. Notice their is no longer a need to specify the column name in the rule using array syntax.

The Visible property is available on each table cell as well and can be used to make the cell content visible/invisible. Here is a rule that will hide the cell contents of the first cell in column a:

Hiding the Minus Icon on a Table Row

You can hide the  minus icon of a table row using a business rule. For example, the designer may not want to allow users to delete rows in a table that is populated from a back end system. Hiding the delete icon on these rows eliminates accidental deletion. The rule must set the table rows deletable attribute. You will not see this property listed on the Table control property pane but it will be listed in the Form Outline tool. 

Let's take a look at a simple example. Users are instructed to enter a capital Y in a table if they are planning on calling a customer. The user enters the "Y" then tabs to the company name column. The minus icon for that row will disappear.  

In this example, the name of the table control is CustomerTable and column 0 in the table is named ContactCustomer.

Here is the rule:

Notice the TableItem deletable property is set to false when a capital Y is entered in the first column. This will remove the minus icon for that row of the table. The for loop cycles through the table rows until the Max# property is reached. 

Dynamically Setting Min/Max in a Table

Min/Max properties of a table can be dynamically set using a business rule. Some scenarios where you might want to do this are:

  1. You have table control in your form. On form.load you want that table to populate with data from a database. 

  2. You have a table control in your form. On selecting a dropdown option, the table populates from a google spreadsheet. 

  3. You have a table control in your form and 2 date controls. The user selects a start and end date. The table populates with the number of rows = the number of days in the date range. 

Setting the Min/Max occurs properties in the rule makes your table essentially read only. 

For example, lets say you have a form that collects how many travelers are planning to travel. When the user enters a number of travelers, the table will populate with the same number of rows as travelers and populate the column for Traveler ID with an ID number. The form will adjust if the number of travelers is changed. 

You can leave the default values for the Min/Max properties of the Table in the Forms designer or set them to any values provided the min value < max value and the max value  > min value.

In this scenario, it is best practice to write 1 rule to handle the table, logic to loop through the rows of the table and itemadded for when another row is added to the table.

For this example, the rule should have the following components:

  1. The first part of your rule should retrieve the results set or as in this example, the user can enter a number in the Number of Travelers field in the form.
  2. The itemAdded statement is needed to determine if you are adding more rows to the table.The first time the table populates this statement will evaluate as false and run the else statement
  3. Evaluate if the number of rows needed is greater than the number or existing rows. If true, the table needs to set the maxoccurs first because the table needs to increase.
  4. if the number of rows needed is less than the number of existing rows (the table needs to shrink) then the table needs to set the minoccurs first.
  5. The rule will loop through the existing rows and set the values in the appropriate columns. If there are still additional rows to be added to the table, after the rule has looped through the existing rows, the itemAdded lines will run.

The images show the table when the user enters 5 as the number of travelers and then changes the value to 3.

The number of Travelers is set to 5.

The number of Travelers is set to 3.

This rule sets the Min/Max properties to the same values so the  plus and  minus icons are not visible. This  prevents users from adding or removing table rows.

Setting the Valid Property for a Table

A section in a repeat will behave differently than a table row when using a rule to set the valid property. For Example, drag and drop a table control into your form. Name it T. Then drag and drop a section into the same form. Name it S. Add a control to the section. Name the control C. Drop the section into a repeat named R. Add this rule to the form.

Clearing Values in a Table

This rule clears the values from all rows in a table. Notice the For loop that iterates over all the rows. Inside the loop a null value is assigned to all the columns in the table row.

You cannot clear an entire table from a rule.

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 are 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.

This rule is useful in a workflow where you want to make a the tab named Review visible only for the workflow activity named Manager Review. See Built-in Data for more details on _data.getParameter and flow.activity.name.

form.unload

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 flow.

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 start 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 a invisible control.

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 flow, it is unloaded as well. form.deactivate was added for completeness. The rulein 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 Live Forms screenflow or multiuser workflow using the Navigation toolbar. Previous and Next buttons are available on mobile devices for this functionality.

Flow designers should consider this navigation when writing business rules. Steps in a screenflow are r/w since they are all performed by the sam euser 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 whenever a R/W step is loaded for the first time and every time it is displayed.

Form.activate and form.deactivate are 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 optional. Text 2 is not visible and not required initially.Step 1 has a form.load rule that makes Text 2 visible and required when the screenflow navigates to Step 2.

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

  • Load S1 – 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 S1 – activate triggers because the step is loaded for the first tim

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

  • Deactivate S1
  • Unload S1
  • Load S2 – the flow 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 S2 – this runs because step 2 is loaded for the first time

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 S2
  • Unload S2
  • Activate S1

form.load is not triggered, and Text 2 is not visible but it is still required. When the user clicks Continue to move to step 2 the screenflow does not move forward.

If the rule is written based on the form.activate event, here’s what happens:

  • The user initiates the screenflow.
    • Load S1 – the form.load is triggered since step 1 is being run for the first time. Text 1 is visible and optional  and Text 2 is not visbile and not required
    • Activate S1 – activate triggers because the step is loaded for the first time
  • The user clicks continue and the flow navigates to Step 2. Note Step1 is deactivated and unloaded and Step 2 is loaded and activated.
    • Deactivate S1
    • Unload S1
    • Load S2 – the flow 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 S2 – this runs because step 2 is loaded for the first time
  • The user navigates back to step 1 without filling in Text 2. Note Step 1 is only activated.
    • Activate S1
  • The form.activate event is triggered, the rule runs . The visible and required properties for Text 2 evaluate to false
  • When the user clicks Continue to move to step 2 the screenflow moves forward. The user fills in Step 2, clicks Finish and completes the screenflow.

For multiuser flows, form.load iand form.activate are triggered when the step is displayed for the first time. form.activate is not triggred when navigating backwards via the Task List as these steps are Read Only. The Activity assigned to the current user will load only once but will activate every time they are loaded in a particular session.

Geo Location

Rules can be used to save a snapshot of location information of any form. For example, an insurance company may want to capture the GPS location of their representatives filling out a form used for audit purposes. The designer can use the Live Forms Geo Location feature in conjunction with rules like the ones shown in the examples below to accomplish this. When the form loads in the browser, the user will be prompted by to allow/disallow the use of location services. If permission is granted, the position will be calculated and server will be updated via an Ajax which causes the rule to fire. If the user denies permission or there is a timeout, the server will get an Ajax with an error.

Use the special rule identifier, form.positionUpload, to set up a rule in a form that will execute every time the form location is updated. See Rules Position Data for the complete list of available position.* data that you can access from your rules.

Here is an example of a location tab on a Police Report form.

Checking the Detailed Loc checkbox in the Form Property pane and implementing a rule like the one shown will go to Google Maps to get additional information and a map associated with the location.

When you run the form (unless you get a timeout or error) the address will automatically get filled in and the Google map will display.  

Sequential Numbers

The Google Spreadsheet connector can also be used to generate unique sequential numbers. This technique should not be used if you have multiple people using the form at the same time as it's possible that two people simultaneously opening the same form could get the same sequential number.

In this example we have a checkbook form where we want to initialize a field named CheckNum with the next sequential check book number when the form loads. Here is our Google spreadsheet:

Here is the rule that reads the next sequential number from the spreadsheets and updates plus 1. Note this rule uses http headers to provide authentication information and passes the Google sheet and worksheet names as query parameters. This is the recommended approach.

  • Replace <Google User ID>  and <Google Account access token> with your information in the user and password headers.
  • Replace the ssname - Sequential Number Generator - with the name of your Google sheet.
  • Replace the wsname - Sheet1 - with the name of the worksheet (tab) in your Google sheet.

See this topic in the Google Connector documentation  for more details.

Unique ID

Forms such as invoices, bills of lading, etc often need to be stamped with a unique ID. The Sequential Number example is one approach, however it has some limitations. One is that you must guarantee that only one person at a time is filling out your form. This is because there is no mutex around the read and update of the Google spreadsheet cell.

Here is a simpler method if your unique IDs do not need to be sequential. The data named form.id is guaranteed to be unique for every new form instance. You can just use it as follows:

An another approach is using the javascript Date method as follows.

Upload Control

Display Uploaded Image

A rule can dynamically display an image uploaded to your form via the upload control. In this example the upload control is named 'u'. The form also must contain a message control as a place holder for displaying the uploaded image. The rule dynamically creates a URL to the uploaded image in the Live Forms temporary attachment repository. The upload control's value 'u.value' is a GUID that uniquely identifies the attachment. The uploaded image will be included in the submission PDF.

Here is the example form before and after the user has upload the frevvo.logo.orange.png image:

This rule is a bit more complex to handle the case where the user uploaded multiple images via the upload control.

Dynamically Set Min/Max Properties

There are two properties, minFiles and maxFiles, associated with the Upload control that can be read or changed at runtime using a business rule. This is a way to dynamically control the number of attachments uploaded to your form/flow.

Here is a simple form with a Radio control named FilestoUpload and Upload control named UploadFiles. The options for the Files to Upload are: none, one or many. The Enabled property for the Upload control is unchecked in the designer.

The requirements for the rule are:

  • If the user selects none for the Files to Upload control, then we do not want to allow any files to be uploaded - disable the Upload control
  • If the user selects one then we want to restrict the file uploads to 1 - set minFiles and maxFiles to 1.
  • If the user selects many then we want to allow no more than 10 attachments - set minFiles to and MaxFiles to 10.

 

Making the Upload Control Required

You can set the minfile and maxfile properties using a business rule without supplying values for the Min/Max properties in the form/flow designers. In this simple form, there is a Radio control with 2 options and an Upload control with no values specified for the Min and Max properties.

Selecting the "Yes" option for the Radio control named TrainingCourse triggers the rule that sets the minFiles and maxFiles of the Upload control named Certificate, making it required. Selecting "No" sets these properties to 0, removing the requirement.

Construct Form URL

A rule can dynamically construct the URL to itself. This can be handy when you want to add a link to your form's URL to an email message or to the form action display message. In this example FormURL is the name of a text control in your form.

Now FormURL can be used as a template in your display message as shown below.

Search Popup

Live Forms forms can initialize dynamically from backend systems. A common form design pattern is the master/detail. An example of master/detail is a form that contains an order number or employee Id. When the user enters an existing Id into the form field you want all other form fields to populate dynamically from values in a database. This is done using a form created from XSD data source generated by the  database connector. This part of the master/detail form design pattern needs no business rule. It happens automatically using the Doc Action manually set document URIs. See the  DB Connector Tutorial for complete detail on how to initialize your form using a Doc Action document URI to your database.

This form was created from employee.xsd generated by the Live Forms database connector. The master Id is a control from that XSD named racfid. The key to this design pattern is in using the master Id in the form's doc action document URI. In this example the form's doc action document URI for the employee document is set to:http://localhost:8082/database/myqset/employee?racfid={racfid}.

Often the master Id is a cryptic number not easily remembered by people using your form. It is a common and useful form design pattern to populate the master Id using a lookup search.

Here is an example form that allows user to view existing employee records and to update their information.

If you know the RACF ID for an employee you can simply type it into that field. If the RACF ID is found in the database the form will automatically populate all other fields from the database (because of the doc action document uri setting). However if you do not know the employee's RACF ID you can click the Find Employee trigger.

This trigger control is named FindEmployee and fires the following rule that makes the search condition section control visible.

The section control contains controls that are the search criteria for finding a RACF ID based on other pieces of information you may know about an employee such as name, type, email address. The values entered into the search criteria can be partial values. For instance entering a name "Smith" will find all employees whose name contains the letters "Smith". If you also select email, it will find all employees whose name contains "Smith" and have an email address containing the string "frevvo".

This is the rule that fires when you click the trigger control named Search.


The Search returns one or more matches and dynamically populates a dropdown control named SearchResults. You can change the search criteria to narrow or expand you search. When you select one of the matches from the SearchResults dropdown this 3rd rule executes to copy the selection into the RACF ID control.

Once the value is copied into RACF ID the form automatically loads all other values in the form from the database. This is due to the form action document Uri setting.

The values in the employee loaded into the form can now be edited. When the users clicks the form's submit button the values will automatically be updated in the database record. This is due to the form action document Uri setting.

LDAP Custom Attributes

You can use a business rule to pull custom attributes from your LDAP server into your form. You will have to modify your LDAP configuration and write a rule using _data.getParameter. Details are explained here.

 

 

 

 

 

 

 

 

if (StartDate.value.length > 10) {
StartDate.valid = false;
StartDate.status = 'Invalid. Please check that the date is entered in the mm-dd-yyyy format';
} else {
StartDate.valid = true;
}
  • No labels