Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Previous Section | Next Section

...

  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. Copy/Paste the code below in the Rule Editor. In the Rule area, type or copy/paste the following. 

    Code Block
    languagejavascript
    linenumberstrue
    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

...


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 TotalsSubTotals

    In the Rule area, type or copy/paste the following. 

  3. Code Block
    languagejavascript
    linenumberstrue
    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; var x = OrderInformationRepeat.itemRemoved;

    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 sum in the Expressions field and click on the sum function when it displays in the dropdown 

    9. Select the Subtotal control then add the closing parenthesis
  4. Click Finish then click on the Image Added 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

Expand
titleClick here to see this rule in the Visual Rule Builder

 Image Added

Rule: Calculate 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 Image Added 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 sum in the Expressions field and click on the sum function when it displays in the dropdown 

    9. Select the Subtotal control then add the closing parenthesis
  4. Click Finish then click on the Image Added 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 

 

 

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. The last line triggers the rule whenever a row is deleted from the table.

 

 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.

...