Expressions

Last modified: April 21, 2023

1 Introduction

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

Named items (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). Expressions can also include Mendix system items which contain information about the current user session. See System Items, below.

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, and the CRM.Customer_Order association of the customer object is referred to as $customer/CRM.Customer_Order).

Attributes of associated objects can be accessed using multiple slashes (for example, the Number attribute of a single associated CRM.Order is referred to as $customer/CRM.Customer_Order/CRM.Order/Number).

You can combine functions in an expression. In this case, 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:

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

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

1.1 Examples

For example, you have an object called package with two attributes: weight (decimal) and shippingCosts (decimal). If the weight of a package is less than one kilogram, there are no shipping costs. Otherwise, the shipping costs are €5.00. The expression for changing the shippingCosts attribute is:

1
if $package/weight < 1.00 then 0.00 else 5.00`

Evaluating the expression:

1
$emptyObject/attribute != $validObject/attribute or $emptyObject = empty

will always return false, as long as emptyObject is empty. The second part of the statement never gets evaluated.

To have both checks evaluated, the order of statements needs to be reversed:

1
$emptyObject = empty or $emptyObject/attribute != $validObject/attribute

This way the first statement gets evaluated.

1.2 Regular Expressions

Regular Expression resource documents cannot be used in expressions. However, the format of regular expressions, sub-expressions, and quantifiers used in regular expression strings is the same as the ones described in the Expression section of Regular Expressions.

2 System Items

Mendix provides you with a number of system items which describe the current user’s session. You can use these in the same way as any other named item.

2.1 $currentUser

This is an object of type System.User which contains the attributes for the currently signed-in user.

2.2 $currentSession

This is an object of type System.Session which contains the attributes for the current user session.

3 Unary Expressions

4 Arithmetic Expressions

5 Relational Expressions

6 Special Checks

7 Boolean Expressions

8 If Expressions

  • if – performs a conditional action

9 Mathematical Function Calls

  • max – the maximum of a list of numbers
  • min – the minimum of a list of numbers
  • round – the rounding of a floating-point number, optionally to a specified 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

10 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
  • isMatch – matches a regular expression
  • replaceAll – replaces the occurrences of a sub-string
  • replaceFirst – replaces the first occurrence of a sub-string
  • String concatenation ( + ) – concatenates strings
  • urlEncode – converts a string to be used in a URL
  • urlDecode – converts a string back from a URL

11 Date Creation

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

11 Begin-of Date Function Calls

  • BeginOfDay – calculates the beginning of the day compared to the initial date
  • BeginOfWeek – calculates the beginning of the week compared to the initial date
  • BeginOfMonth – calculates the beginning of the month compared to the initial date
  • BeginOfYear – calculates the beginning of the year compared to the initial date

12 End-of Date Function Calls

  • EndOfDay – calculates the end of the day compared to the initial date
  • EndOfWeek – calculates the end of the week compared to the initial date
  • EndOfMonth – calculates the end of the month compared to the initial date
  • EndOfYear – calculates the end of the year compared to the initial date

13 Between Date Function Calls

14 Add Date Function Calls

15 Subtract Date Function Calls

16 Trim to Date

17 To String

See To String for details.

18 Parse Integer

See Parse Integer for details.

19 Parse & Format Decimal Function Calls

20 Parse & Format Date Function Calls

21 Enumerations in Expressions

  • getCaption – gets the caption of an enumeration value in current language
  • getKey – gets the technical name of an enumeration value