Last update: Edit

1 Introduction

Expressions changes a value based on a function or combination of functions.

You can use expressions for workflows, pages, and microflows. The expressions are usually used to configure a condition for a certain activity or property, for example, a condition for a decision in a microflow or a workflow.

You can use expressions for the following elements in a workflow:

Expressions can be used in the following properties on a page:

  • Conditional editability of a widget
  • Conditional visibility of a widget
  • Content property of a text widget

Expressions can be used for the following activities in a microflow:

  • Change Object
  • Change Variable
  • Create Object
  • Create Variable
  • Decision
  • End Event

For more information on setting and changing values for microflow activities, see Set & Change a Value for Different Activities in the Microflows.

2 Writing an Expression

Named items in microflows and workflows (for example, objects, lists, or variables) can be called in an expression by inserting the name of the item and adding a dollar sign (for example, $Customer could refer to an object named Customer).

Attributes and associations of objects are accessed using a slash (for example, the Name attribute of the customer object is referred to as $Customer/Name).

You can use brackets to determine the priority and associativity of calculations. For example, the SellingPrice is being calculated based on the default Price and Discount attributes:

$CurrentPrice/Price - (($CurrentPrice/Price **div** 100) * $OrderLine/Discount)

Arithmetic functions (subtraction, dividing, and multiplying) are being combined here.

You cannot type plain text in an expression, text needs the be written with single quotation marks (') around it. For example, if you would like to return a string Mendix, you need to write it as 'Mendix'.

You can use a list of suggestions to help you write an expression. Use Ctrl + Space shortcut to display this list. Suggestions can be divided into the following categories:

  • Variables and their attributes – variables or attributes that are available in a current microflow, on a page, or in a workflow
  • Enumeration values – values of enumeration type of attributes that can be used in an expression
  • Functions – operations you can use in an expression (for more information, see the Expression Types section below)
  • Keywords – key phrases or words that you can use in an expression (for example, empty – a value that can be used to check if a variable is empty)
  • Booleans – true or false keywords
  • Operators – code elements that perform logical or mathematical operations; you can use Boolean or relational expressions (for more information, see the Expression Types section below)

If there is an errors in the expression, the place where the error is, is highlighted red and an error message is shown when you hover over it. In some cases there are quick fixes available to quickly solve the issue.

2.3 Expression Examples

Examples that illustrate how expressions can be used are described below.

2.3.1 Example 1

You have a Decision in a microflow and you would like to write an expression that checks whether the customer grade is gold and the price of the order is more than 100 (you can configure a discount after the Decision that is allowed if this expression is true):

The expression will look the following way:

2.3.2 Example 2

You add a Decision to a microflow to check if an object (in the example below the object is Customer) exists. And you also check if the Customer’s name matches a particular one (in the example below Customer’s name is Mendix). The expression will look the following way:

2.3.3 Example 3

You have a user task in a workflow and would like to add a Due Date as a reminder that the user task should be done by the day after tomorrow. You can write the following expression for it:

User Task Expression

3 Expression Types

The list of expressions that are used in Studio the most is represented below. For the full list of available expressions, see Expressions in the Studio Pro Guide.

3.1 Unary Expressions

3.2 Arithmetic Expressions

3.3 Relational Expressions

3.5 Boolean Expressions

3.6 Mathematical Function Calls

  • max – the maximum of a list of numbers
  • min – the minimum of a list of numbers
  • round – rounds a number to a certain precision
  • random – random number generation
  • floor – the rounding of a floating-point number down
  • ceil – the rounding of a floating-point number up
  • pow – the exponentiation
  • abs – the absolute value

3.7 String Function Calls

  • toUpperCase – converts the string to upper-case
  • toLowerCase – converts the string to lower-case
  • length – the string length
  • substring – gets a part of a string
  • find – gets a sub-string position
  • findLast – gets the last sub-string position
  • contains – contains the sub-string
  • startsWith – determines whether a string starts with the specified sub-string
  • endsWith – determines whether a string ends with the specified sub-string
  • trim – removes the leading and trailing whitespace
  • replaceAll – replaces the occurrences of a sub-string
  • replaceFirst – replaces the first occurrence of a sub-string
  • String concatenation ( + ) – concatenates strings

3.8 Date Creation

  • dateTime – creating a date value using the server’s calendar

3.9 Between Date Function Calls

3.10 Add Date Function Calls

3.11 Parse & Format Decimal Function Calls

4 Read More