Orbeon Forms
  • Getting started
  • Installation
    • Logging
    • Configuration banner
    • Docker
    • Azure
    • Tomcat
    • WildFly
    • WebSphere
    • WebLogic
    • GlassFish
    • Caches
    • Replication
    • Upgrading
  • Configuration
    • Properties
      • General
        • HTTP client
      • Form Runner
        • Detail page
          • Attachments
          • Email properties
          • PDF
          • Table of contents
        • Persistence
        • Summary page
      • Form Builder
      • XForms
    • Advanced
      • Workflows
      • Session management
      • State handling
      • Client-side error handling
      • Clustering and High Availability
      • Configuring a Form Runner eXist database
      • Creating a production WAR
      • Environments
      • JavaScript and CSS assets
      • Limiter filter
      • Run modes
      • Security
        • Content-Security-Policy header
      • SAP Hybris Module
      • XForms logging
    • Troubleshooting
      • Troubleshooting with the orbeon.log
      • Memory and threads
      • Relational database logging
      • Misc
  • Form Builder
    • Form settings
      • Time window
    • Form editor
      • Form area
      • Toolbox
      • Buttons bar
      • Control settings
      • Dependent fields and sections
      • Validation
      • Choices editor
      • Publishing
      • Cut, copy and paste
      • Section and grid settings
      • Section settings
      • Grid settings
      • Quick control search
      • Repeat settings
      • Repeated grids
      • Undo and redo
      • Keyboard shortcuts
    • Formulas
      • Examples of formulas
      • Formulas inspector
      • Formulas console
    • Summary page
    • Form localization
    • Advanced
      • Edit source
      • Services and actions
        • HTTP services
        • Database services
        • Simple Actions
        • Action Syntax
        • Action Syntax examples
        • Synchronizing repeated content
      • Testing a form in web mode
      • Testing PDF production
      • Testing offline functionality
      • Email Settings dialog
      • Field-level encryption
      • Messages
      • Section templates
      • Template syntax
      • XML Schemas support
      • Extensibility
        • Extension API
        • Integration
        • Toolbox component metadata
  • Form Runner
    • Overview
      • Terminology
    • Pages
      • Landing page
      • Published Forms page
      • Forms Admin page
      • Summary page
    • Components
      • Alert dialog
      • Attachment
      • Autocomplete
      • Captcha
      • Character counter
      • Checkbox input
      • Currency
      • Date
      • Dropdown date
      • Static and dynamic dropdown
      • Error summary
      • Grid
      • Handwritten signature
      • Hidden field
      • Image
      • Image annotation
      • Image attachment
      • Number
      • Open selection
      • Repeater
      • Formatted Text / Rich Text Editor
      • Section
      • Single-selection tree
      • Source code editor
      • Time
      • US phone
      • US state
      • Video
      • Video attachment
      • Wizard
      • XForms inspector
      • Yes/No answer
    • Features
      • Automatic calculations dependencies
      • Datasets
      • Excel and XML import
      • Excel and XML export
      • Summary page Excel Export
      • Form definitions and form data Zip Export
      • Purging historical data
      • Lease
      • Localization
      • Supported languages
      • Mobile support
      • Multitenancy
      • Form Runner navigation bar
      • PDF production
        • Automatic PDF
        • Automatic PDF header and footer configuration
        • PDF templates
      • Responsive design
      • Revision history
      • S3 storage
      • Simple data migration
      • TIFF production
      • Versioning
      • Wizard view
      • Workflow stage
    • Persistence
      • Using a relational database
      • Relational database schema
      • Purging old data using SQL
      • Auditing
      • Autosave
      • Database support
      • Flat view
    • Linking and embedding
      • Linking
      • Java Embedding API
      • JavaScript Embedding API
      • Liferay full portlet
      • Liferay proxy portlet
      • Securing Form Runner access
      • Form Runner offline embedding API
      • Angular component
      • React component
    • Access control and permissions
      • Users
      • Login & Logout
      • Deployed forms
      • Form fields
      • Editing forms
      • Owner and group member
      • Organizations
      • Scenarios
      • Token-based permissions
    • Styling
      • CSS
      • Grids CSS
      • Automatic PDF styling and CSS
    • APIs
      • Authentication of server-side service APIs
      • Persistence API
        • CRUD API
        • Search API
        • List form data attachments API
        • Form Metadata API
        • Lease API
        • Reindexing API
        • Caching
        • Versioning
        • Revision History API
        • Zip Export API
        • Custom persistence providers
      • Other APIs
        • Connection context API
        • Duplicate form data API
        • File scan API
        • Form Runner JavaScript API
        • Generate XML Schema API
        • PDF API
        • Publish form definition API
        • Run form in the background API
      • Data formats
        • Form data
        • Date and time
        • Form definition
    • Architecture and integration
      • Architecture
      • Access form data
      • Integration
    • Advanced
      • Buttons and processes
        • Simple process syntax
        • Core actions
        • Form Runner actions
          • Save action
          • Send action
          • Email action
        • XForms actions
        • Predefined buttons, processes and dialogs
        • Summary page buttons and processes
      • Custom dialogs/model logic
      • Services
      • Singleton form
      • Monitoring HTTP requests
  • XForms
    • Core
      • Attribute Value Templates (AVTs)
      • Binds
      • Validation
      • Variables
      • Keyboard focus
      • XForms JavaScript API
      • Error handling
        • Detailed behavior
      • Model-Bind variables
      • XForms 2.0 support
    • Events
      • Standard support
      • UI refresh events
      • Keyboard events
      • Extension events
      • Extension context information
      • Other event extensions
    • Actions
      • Repeat, insert and delete
      • Scripting actions
      • Extensions
    • Controls
      • Label, hint, help
      • Input
      • Output
      • Text area
      • Button
      • Upload
      • Dialog
    • Submission
      • Standard support
      • JSON support
      • Asynchronous submissions
      • Caching extension
      • Other submission extensions
    • XPath
      • Type annotations
      • Expression analysis
      • Tips
      • Compatibility
      • Standard functions
      • Maps and arrays Functions
      • Extension functions
        • Core functions
        • Utility functions
        • Model functions
        • Controls functions
        • XML functions
        • JSON functions
        • HTTP functions
        • Form Runner functions
        • Other functions
        • Deprecated functions
    • XBL components
      • FAQ
      • Guide
        • XBL Tutorial
        • Bindings
        • XForms models
        • Including content
        • Event handling
        • Conventions
        • Map XBL example
        • Learning from existing components
      • Advanced topics
        • XBL Modes
        • JavaScript companion classes
        • XBL library
        • Extensions
        • Attachment controls
    • XForms tutorial
      • Introduction
      • Installation
      • The Hello application
      • The Bookcast application
        • The basic app
        • Database access
        • Polishing the app
        • Adding a feed
    • Using XForms from Java apps
  • XML Platform
    • Page Flow Controller
      • Basics
      • XML submission
      • Navigating between pages
      • Paths and matchers
      • Other configuration elements
      • Typical combinations of page model and page view
      • Examples
      • Authorizing pages and services
    • Processors
      • URL generator
      • Request generator
      • PDF to image converter
    • Resources
      • Resource managers
      • Setting up an external resources directory
    • Other
      • Binary and text documents
  • FAQ
    • Licensing
    • PE and Dev Support
    • Form Builder and Form Runner
    • Resources and support
    • Other technical questions
  • Contributors
    • Automated tests
    • Building Orbeon Forms
    • Localizing Orbeon Forms
    • Validation functions
    • Contributor License Agreement
  • Release notes
    • Orbeon Forms 2022.1.9
    • Orbeon Forms 2024.1.1
    • Orbeon Forms 2023.1.7
    • Orbeon Forms 2024.1
    • Orbeon Forms 2023.1.6
    • Orbeon Forms 2023.1.5
    • Orbeon Forms 2021.1.11
    • Orbeon Forms 2022.1.8
    • Orbeon Forms 2023.1.4
    • Orbeon Forms 2023.1.3
    • Orbeon Forms 2023.1.2
    • Orbeon Forms 2022.1.7
    • Orbeon Forms 2023.1.1
    • Orbeon Forms 2023.1
    • Orbeon Forms 2022.1.6
    • Orbeon Forms 2021.1.10
    • Orbeon Forms 2022.1.5
    • Orbeon Forms 2021.1.9
    • Orbeon Forms 2022.1.4
    • Orbeon Forms 2022.1.3
    • Orbeon Forms 2021.1.8
    • Orbeon Forms 2022.1.2
    • Orbeon Forms 2022.1.1
    • Orbeon Forms 2022.1
    • Orbeon Forms 2021.1.7
    • Orbeon Forms 2021.1.6
    • Orbeon Forms 2021.1.5
    • Orbeon Forms 2021.1.4
    • Orbeon Forms 2021.1.3
    • Orbeon Forms 2021.1.2
    • Orbeon Forms 2021.1.1
    • Orbeon Forms 2021.1
    • Orbeon Forms 2020.1.6
    • Orbeon Forms 2019.2.4
    • Orbeon Forms 2019.1.2
    • Orbeon Forms 2018.2.5
    • Orbeon Forms 2018.1.4
    • Orbeon Forms 2020.1.5
    • Orbeon Forms 2020.1.4
    • Orbeon Forms 2020.1.3
    • Orbeon Forms 2020.1.2
    • Orbeon Forms 2019.2.3
    • Orbeon Forms 2020.1.1
    • Orbeon Forms 2020.1
    • Orbeon Forms 2019.2.2
    • Orbeon Forms 2019.2.1
    • Orbeon Forms 2019.1.1
    • Orbeon Forms 2019.2
    • Orbeon Forms 2019.1
    • Orbeon Forms 2018.2.4
  • Release history
  • Use cases
  • Product roadmap
  • Index of features
Powered by GitBook
On this page
  • Formulas and XPath
  • Examples of formulas
  • Referring to control values from formulas
  • Basic usage
  • Variables in depth
  • Where you can use variables
  • Resolution of repeated controls
  • Renaming of controls and formulas
  • Where do formulas appear?
  • Control Settings dialog
  • Section/Grid Settings dialog
  • Actions
  • Examples
  • See also
  1. Form Builder

Formulas

PreviousKeyboard shortcutsNextExamples of formulas

Last updated 8 months ago

Formulas and XPath

In Orbeon Forms, formulas are expressed using XPath, a standard expression language for XML. It does not allow you to modify XML data, but it allows you to query XML data and compute values.

For those familiar with Microsoft Excel or other spreadsheet software, you can think of formulas with Orbeon Forms as what follows the "=" sign in a spreadsheet. It is similar to that, but with a slightly different syntax and set of rules.

In general, you don't need to know about XPath in Form Builder, with the exception of some properties in the Control Settings and Section Settings dialogs. Formulas are considered an advanced feature of Form Builder, which might require some programming knowledge.

NOTE: Incorrect XPath expressions may cause the form to behave improperly, so caution must be applied.

Examples of formulas

See .

Referring to control values from formulas

Basic usage

To refer to a form control value from a formula, use the variable notation $foo where foo is the control name. For example:

$price * $quantity

This assumes a form control named "price" and another form control named "quantity".

Variables in depth

In a formula, when referring to $price, the result is actually an XML node, as this is how Orbeon Forms stores data internally. Think of a node as a container for a value:

<price>4.99</price>

There are two ways to obtain a value from this node:

  • using the string() function

    • this returns, of course, a value of type string

    • example: $price/string() or string($price)

  • using the data() function

    • this returns a value of the type associated with the associated form control

    • example: $price/data(.) or data($price)

Now in many cases, XPath gets the value for you without calling string() or data(). For example when you perform a multiplication:

$price * $quantity

Here, XPath "sees" that the multiplication cannot apply to nodes, and automatically fetches ("atomizes") the value from the nodes. In this case, if the associated form control has type "Decimal", then the values will be retrieved from the nodes and converted to decimal numbers as if you had used the data() function explicitly:

data($price) * data($quantity)

Note that the multiplication will fail if the form controls do not contain valid decimal numbers.

The data() function can be a little tricky because of this. Now say you'd like instead to concatenate the text of those nodes containing decimal values even if the don't contain valid decimal values. Then you have to explicitly use the string() function:

concat('Price: ', string($price), 'Quantity: ', string($quantity))

Where you can use variables

You can use the variable notation in the following formulas in the Control Settings dialog:

  • Required

  • Validation

  • Calculated Value

  • Initial Value

  • Visibility

  • Read-Only

[SINCE Orbeon Forms 2022.1]

You can also use the variable notation in the following formulas:

  • Repeated grids and sections:

    • Minimum Number of Repetitions

    • Maximum Number of Repetitions

    • Freeze Repetitions

  • Number and Currency fields

    • Prefix

    • Suffix

  • Dynamic Dropdown:

    • Resource URL

    • Choices formula

    • Label formula

    • Value formula

    • Hint formula

  • Actions

    • Simple Actions

    • Action Syntax

    • Control name

    • Formula

Resolution of repeated controls

When referring to controls that are repeated, for example within repeated grids or repeated sections, a variable can return a sequence of multiple values. Each value corresponds to a repeated control.

However, not all controls in the form are necessarily selected. Instead, the "closest" controls are selected, as follows:

  • The closest enclosing repeat iteration between the location of the formula and the control identified by the variable is identified. If there is none, then this is the top-level of the form.

  • Then all the controls within that iteration, or within the entire form when there is no such iteration, are selected.

For example, consider

  • a repeated grid

  • a decimal field called price on each row

  • an integer field called quantity on each row

  • a decimal text output field called row-total on each row

  • a decimal text output field called total below the grid

Calculated value expression for row-total:

$price * $quantity

The row-total calculated value applies to the closest price and quantity controls, that is, those on the same row, and each row gets its own row total.

Calculated value expression for total:

sum($row-total[string() castable as xs:decimal], 0.0)

On the other hand, the total calculation is outside the repeat, and when it refers to $row-total, all row-total values are returned. Therefore, the sum applies to all the row-total values (assuming they can be cast as xs:decimal, in this example).

TODO: Is this the same as using fr:control-string-value('$price', false()), or is there a subtle difference?

Renaming of controls and formulas

[SINCE Orbeon Forms 2019.1]

When a control or section or grid is renamed, dependent formulas which use the variable notation $foo (where foo is the control name) are automatically updated.

[SINCE Orbeon Forms 2022.1]

In addition, other references which use the variable notation $foo where foo is the control name, are automatically updated, including:

  • Repeated grids and sections:

    • Minimum Number of Repetitions

    • Maximum Number of Repetitions

    • Freeze Repetitions

  • Number and Currency fields

    • Prefix

    • Suffix

  • Dynamic Dropdown:

    • Resource URL

    • Choices formula

    • Label formula

    • Value formula

    • Hint formula

  • Actions

    • Simple Actions

    • Action Syntax

    • Control name

    • Formula

Where do formulas appear?

Control Settings dialog

In the Control Settings dialog, formulas are used to specify the following aspects of a control.

Validations and alerts

  • Constraint: Boolean expression specifying whether the control is valid.

    • If this field is left blank, then the validity of the control depends on the data type and the "Required" option.

    • Otherwise, the control is valid if in addition to all the other constraint being met, the result of the Boolean expression is true().

Formulas

  • Visibility:

    • Specifies whether the control is visible. This can be either "Yes" (default), "No", or an XPath formula.

    • If a formula is specified, the control is visible only if the formula evaluates to true().

  • Read-Only:

    • Specifies whether the control is read-only (not editable). This can be either "Yes", "No" (default), or an XPath formula.

    • If a formula is specified, the control is editable only if the formula evaluates to false().

  • Initial value:

    • String expression returning the initial value of the control when the form first shows. This is only applied in new mode.

    • Default: the value set into the field at design time (usually a blank value).

  • Calculated Value:

    • String expression specifying a calculated value of the control which updates while the form user interacts with the form.

    • Default: the default value of the control, or the value entered by the form user.

Section/Grid Settings dialog

In the Section/Grid Settings dialog, formulas are used to specify the following aspects of a section or grid:

  • Visibility: Specifies whether the section or grid is visible. This can be either "Yes" (default), "No", or an XPath formula, in which case the section or grid is visible only if the formula evaluates to true().

  • Read-Only: Specifies whether the section or grid is read-only (not editable). This can be either "Yes", "No" (default), or an XPath formula, in which case the section or grid is editable only if the formula evaluates to false().

[SINCE Orbeon Forms 2020.1]

In the Form Settings dialog, an XPath expression can be used to specify whether the entire form is read-only (not editable).

Actions

In the Section/Grid Settings dialog, formulas are used to specify the following aspects of a section or grid:

TODO

Examples

See also

  • Blog posts

See also the blog post .

See .

Examples of formulas
Template parameters
Improvements to variables in formulas
Template parameters
examples of formulas
Examples of formulas
Form Builder Validation
Formulas inspector
Better formulas with XPath type annotations
Formulas for summing values, done right
Control required values with formulas in Orbeon Forms 4.7
Improvements to variables in formulas
XForms Validation
Validations
Formulas
Basic Settings and Formulas
When the internal data format matters