Live Forms Latest - This documentation is for Live Forms 8.1. v8.1 is a Cloud Only release. Not for you? Earlier documentation is available too.

Skip to end of metadata
Go to start of metadata

Previous Section | Next Section

Example - Order Items Rules

Now, we'll take a look at some business rules. We're going to add several rules to automate parts of the form. We will use the Live Forms Visual Rule Builder to create the code for all but one of these rules.

Update the Client Information Form

  1. Click the Copy icon to make a copy of the Order Info form. Then, click the Edit icon to open the Form Designer.
  2. In the Properties Panel, change the form name to Order Info Rules.
Rule: Automatically Set Date to today's date
  1. Click the  rules icon on the toolbar. Create a new rule and click the icon to edit it.
  2. Change the name of the rule to: Initialize form
  3. Click on the Rule Builder button.

    1. Click Next to go to the Action wizard.

    2. Click the Add Action button on the top right of the Action Wizard

    3. Select TodaysDate from the first dropdown. TodaySDate is the Name of the Date control at the top of the form. If your control is named something else, select that control from the dropdown.replace TodaySDate below with that name

    4. Select to from the second dropdown

    5. Type today in the Expression field and click on the today function when it displays in the dropdown 

  4. Click Finish then click on the save and test icon. Now, when the end user first starts using the form, the Date control at the top will be set to today's date. No need for the user to type it in.

     Click here to see this rule in the Visual Rule Builder

     

Rule: Set Price from Item

When the user selects an item in any of the rows in the Order Items table, we want the price of that item to be displayed automatically. Normally, this price information would come from a back end database or other system but we're just hard-coding the values in the rule for the time being.

  1. Click the icon in the toolbar to return to the form. In the Order Items table, select the Price column by clicking on the header. In the Properties panel, uncheck Enabled. The entire column is greyed out.
  2. Go back to the rules editor, create a new rule and edit it. Change the name of the rule to: Set Price for Item.
  3. Click Rule Code then click Edit Code. In the Rule area, type or copy/paste the following. 

    Now, when the user selects an item, the price for that item will be displayed.

Rule: Calculate Subtotals

When an item and quantity are selected in a particular row, we want to compute the price for that item (Subtotal = Quantity * Price) and display it in the Subtotal column for that row.

  1. Click the icon in the toolbar to return to the form. In the Order Items table, select the Subtotal column by clicking on the header. In the Properties panel, uncheck Enabled. The entire column is greyed out.
  2. Go back to the rules editor, create a new rule and edit it. Change the name of the rule to: Calculate SubTotals
  3. Click on the Rule Builder button. You will see the Condition wizard

    1. Click the Add Condition button

    2. Select your Price control from dropdown

    3. Select the "is filled" property from the Property dropdown
    4. Click Next to go to the Action wizard.

    5. Click the Add Action button on the top right of the Action Wizard

    6. Select your Subtotal control from the dropdown.

    7. Select "to" from the second dropdown

    8. Type Price * Quantity in the Expressions field

  4. Click Finish then click on the save and test icon. Now, when the end user selects the item and fills in the quantity, the Subtotal will be calculated for each row of the table

 Click here to see this rule in the Visual Rule Builder
Rule: Calculate Grand Total

When all items and quantities are selected, we want to compute the overall price for all items and display it in the Grand Totals field.

  1. Click the icon in the toolbar to return to the form. Click on the Grand Total control. Uncheck Enabled in the Properties panel. The field is greyed out.
  2. Go back to the rules editor, create a new rule and edit it. Change the name of the rule to: Calculate Grand Total
  3. Click on the Rule Builder button. You will see the Condition wizard

    1. Click Next to go to the Action wizard.

    2. Click the Add Action button on the top right of the Action Wizard

    3. Select your Grand Total control from the dropdown.

    4. Select "to" from the second dropdown

    5. Type sum in the Expressions field and click on the sum function when it displays in the dropdown 

    6. Select the Subtotal field from the dropdown then add the closing parenthesis

  4. Click Finish then click on the save and test icon

 Click here to see this rule in the Visual Rule Builder

Now, the overall Grand Total is automatically calculated and updated with the Subtotal amounts as rows are filled in and added to the table. Try deleting a row in the table. Notice the Subtotal amount for that row is subtracted from the Grand Total 

Live Forms has a powerful Rules engine. You can perform many dynamic actions in your form including the examples above as well as many other actions like connecting to back end systems and retrieving JSON to populate form controls etc The Visual Rule Builder makes it easy to create rules to show/hide parts of the form, automatically fill in user information, make controls required or optional dynamically without writing code, For more information, refer to the Rules Examples documentation.

Previous Section | Next Section

  • No labels