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

Order Items Rules

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.

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. In the Rule area, type or copy/paste the following. TodaySDate is the Name of the Date control at the top of the form. If your control is named something else, replace TodaySDate below with that name. You can also see the list of available names in the Form Outline panel in the Rules canvas.

    if (form.load) {
      TodaySDate.value = frevvo.currentDate();
    }

    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.

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. In the Rule area, type or copy/paste the following.

    for (var i = 0; i < Item.value.length; i++) {
      if (Item[i].value === 'Chevrolet') {
        Price[i].value = 125.75;
      } else if (Item[i].value === 'Chrysler') {
        Price[i].value = 118.75;
      } else if (Item[i].value === 'Ford') {
        Price[i].value = 132.75;
      }
    }

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

Rule: Calculate Subtotal and Grand Total

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

  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 Totals
  3. In the Rule area, type or copy/paste the following. 

     

    var grandtotal = 0.0;
    for (var i = 0; i < Item.value.length; i++) {
      if (Item[i].value.length > 0 && Quantity[i].value > 0) {
        var subtotal = Price[i].value * Quantity[i].value;
        Subtotal[i].value = subtotal;
        grandtotal += subtotal;
      }
    }
    GrandTotal.value = grandtotal;

    Now, when the user selects an item and a quantity, the subtotal for that line and the overall grand total are automatically calculated and updated.

 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 showing/hiding parts of the form, automatically filling in user information, making controls required or optional dynamically, connecting to back end systems and retrieving JSON to populate form controls etc. Form more information, refer to the Rules Examples documentation.

Previous Section | Next Section