Previous Section | Next Section
...
- 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.
- Go back to the rules editor, create a new rule and edit it. Change the name of the rule to: Set Price for Item.
Click Rule Code then click Edit Code. In the Rule area, type or copy/paste the following.
Code Block language javascript linenumbers true 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
...
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 the overall price for all items.
- 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.
- Go back to the rules editor, create a new rule and edit it. Change the name of the rule to: Calculate SubTotals
Click on the Rule Builder button. You will see the Condition wizard
Click the Add Condition button
Select your Price control from dropdown
- Select the "is filled" property from the Property dropdown
Click Next to go to the Action wizard.
Click the Add Action button on the top right of the Action Wizard
Select your Subtotal control from the dropdown.
Select "to" from the second dropdown
Type sum Price * Quantity in the Expressions field and click on the sum function when it displays in the dropdown
- Select the Subtotal control then add the closing parenthesis
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
Expand | ||
---|---|---|
| ||
Rule: Calculate Grand Total
When an item all items and quantity quantities 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 and display it in the Grand Totals field.
- Click the icon in the toolbar to return to the form. In the Order Items table, select the Subtotal column by clicking Click on the header. In Grand Total control. Uncheck Enabled in the Properties panel, uncheck Enabled. The entire column field is greyed out.
- Go back to the rules editor, create a new rule and edit it. Change the name of the rule to: Calculate SubTotalsGrand Total
Click on the Rule Builder button. You will see the Condition wizard
Click the Add Condition button
Select your Price control from dropdown
Select the "is filled" property from the Property dropdownClick Next to go to the Action wizard.
Click the Add Action button on the top right of the Action Wizard
Select your Subtotal Grand Total control from the dropdown.
Select "to" from the second dropdown
Type sum in the Expressions field and click on the sum function when it displays in the dropdown
Select the Subtotal
controlfield from the dropdown then add the closing parenthesis
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
Expand | ||
---|---|---|
| ||
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.. Try deleting a row in the table. Notice the Subtotal amount for that row is subtracted from the Grand Total
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.