Versions Compared

Key

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

...

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. We will build this rule with JavaScript instead of using the Visual Rule Builder so that you can see that supports more than one way to write business rules.

  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. 

    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.

...

 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 etcThe

 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.

...