Calculation Field

Introduction

The Calculation Field allows you to perform a series of arithmetic computations on a set or a series of fields. This feature is available only in Joget's Enterprise Edition.

How does it work?

The easiest way to see how the Calculation Field works is to use the existing built-in App Expenses Claims and look at an existing form. Follow these steps:

  1. Start the Joget Server and open the App Center.
  2. Log in as admin and click the pencil icon on the Expenses Claim to open the Design App.
  3. Under the Form Builder column, click on Expense Claim Form.
  4. Click on the Calculation Field labeled Total Amount $ on the canvas to open up the Configure Calculation Field properties.
  5. Take note of the Variables field. The spECD value refers to another field within the form.
  6. Click the Grid element to open the Edit Grid properties.

    You are summing a specific column from a Form Grid.
    • Form Grid ID: spECD
    • Column in Form Grid: amount
    • Field ID to be filled in: spECD.amount


  7. Click Preview and enter values into the Amount column in the Grid to see the Total Amount $, and automatically add the values.

Configure calculation field

Configuring the Calculation Field involves setting various properties to define how the field behaves and interacts with other fields.

Fields to configure:

  • Label: Element label to be displayed to the end-user.
  • ID: Element ID. A corresponding database table column c_total will be created by declaring it as total. See Form Element for more information about defining the ID and a list of reserved IDs.
  • Variables:
    • Variable Name: Declare a name to store the current row equation result.
      For Example:

      • subtotal
      • discountPercent
      • charges

    • Field ID: Form Field ID to retrieve.
      If you are totaling a form grid column, use this format: formGridId.columnId where the first part before the decimal tells Joget which form grid to use, and the second part after the decimal tells Joget which column in the specified form grid to use for calculation.
    • Multivalue Operation:

      • Sum
      • Avg
      • Min
      • Max

  • Equation: Arithmetic operation using the variables declared above.

    For example:

    • subtotal - (subtotal * discountPercent / 100)
    • subtotal - discountAmount
    • subtotal - charges (Correct)
    • subtotal-charges (Wrong)
    Important:
    • It is essential to include spacing between operators.
    • The position and spacing of all elements of an equation must be exactly as they are to appear in printed form. 

Advanced Options

These options provide additional customization and validation features for the Calculation Field.

Data & Validation

This section allows you to attach validators and configure data-related properties.

Field to configure:

  • Validator: Attach a Form Validator plugin to validate the input value. Validation takes place whenever a form is submitted except when it is submitted as Save as Draft.

Format

Here, you can define the display and formatting options for the calculated value.

  • Formatting Style:
    • US Style Formatting (1,000.00)
    • European Formatting (1.000,00)
  • Number of Decimal: Number of decimals.
  • Prefix: The prefix of the calculated value.
  • Postfix: Postfix of the calculated value.
  • Use Thousand Separator?: Thousand separator toggle.
  • Store as Numeric Value?: Toggle to store as a numeric value instead of a string.

UI

This section deals with the visibility and display options of the Calculation Field.

Fields to configure:

  • Hidden?: Show or hide this element to the end user.
  • Display as Label?: Display the value of the element as plain text.

Workflow

Configure workflow-related properties for the Calculation Field to integrate with workflow processes.

Field to configure:

  • Workflow Variable: If the form is part of a workflow process, upon saving the form by clicking the Save as Draft or Save button, the value in this input field will be saved into the corresponding workflow variable named in this field.
Using a non-existent Workflow Variable name
You will get a warning with the name printed out (e.g., status) in the server log if you attempt to map to a non-existent Workflow Variable.
context attribute status does not exist in process context - adding new attributes to the process context is not allowed
Created by Julieth Last modified by Aadrian on Dec 13, 2024