Low-code designer > Custom forms / Calculated fields

Calculated fields

can automatically calculate field values on app pages. For instance, it can calculate the total price of an order including VAT or a customer discount. The system can also show or hide particular fields depending on conditions.

These options become available when you switch to the Advanced Mode form editing. Go to the Context tab and click on the property you want to set up. In the provided settings window check the Set a formula for the field box or Show only when a condition is met.

CF1

Lets take a look at how these settings work.

Set a formula for the field

начало внимание

This option is only available for String, Number, and Money field types.

конец внимание

If the Set a formula for the field option is enabled, the Formula* field appears. You can add, subtract, calculate and divide the values with the following operators: +, -, *, /. Use parentheses () to define the order of operations.

You can add a variable of the same type as the calculated field to the formula. To do that, click {+} and select the variable from the list.

For example, to the formula for a String property, add String type variables. In case of a Number property, use Number type variables in the formula. If you add a variable of a different type, a validation error will occur.

The only exception is the Money type. In a formula for a Money type property, you can use the Money*Number combination, meaning that you can multiply the value of the Money field by the value of the Number field.
 
Consider the following example.

Lets say a company sells and delivers heating installations. When an order is made, the sales rep enters all the details into the system: the customers name, the goods purchased, the delivery date, etc. They might also want to enter a discount. Since the discount may vary depending, for instance, on the orders size, it is convenient to use a formula to calculate the total amount to be paid.

CF2

To set up this behavior, open the order form for editing. Go to the Context tab and create a new Total with discount property. Select the Money type since we are calculating the final amount to be paid.

CF3

Check the Set a formula for the field box. The required Formula field will appear. Click on the plus symbol {+} in the right corner of the line. A list of app fields with pop up. Select the Total amount variable of the Money type (this is the right table column, where the total price of the order is calculated before the discount is applied) and the Discount variable of the Number type (this is the field where the sales rep enters the discounts amount when registering the order).

Your final formula shall look as follows:

CF4

Save the changes. Now, when filling in the order form, the sales rep will enter the purchased products, the number of items purchased, and the discount amount. The system will automatically calculate the total amount to be paid minus the discount.  

CF5

Show fields based on conditions

Sometimes you need to hide or show fields on the form depending on certain conditions. Lets say our company provides different delivery options, including pickup and courier delivery. When a sales rep registers a new order, he or she specifies the delivery method selected by the customer. If the customer has selected courier delivery, an additional address field will appear on the form. In the case of pickup, the field will stay hidden.

CF6

To set up this behavior, open the order form for editing. Go to the Context tab and create a new Delivery address property. Check the Show only when a condition is met box and then click on the Set up conditions link.

CF7

In the pop-up, you can now set up the show condition for the field. If the conditions are not met, the field will remain hidden.

CF8

  • Operand 1, 2. Select a property from the app's context or specify a particular value.
  • Operation. Select the operator for checking this condition.

If you want to set up multiple conditions, you have to link them with logical operators that will be used for checking the conditions. The field will be shown if the result is true.

Operators:

  • AND. The result is True if both conditions are met.
  • OR. The result is True if at least one of the conditions is met.
  • OR NOT. The result is True if at least one of the conditions is not met.
  • AND NOT. The result is True if both conditions are not met.

Note that conditions are checked in the order they are listed.

Found a typo? Highlight the text, press ctrl + enter and notify us