Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Expressions

Expressions in MDL are used in conditions, attribute assignments, variable assignments, and log messages within microflows. They follow Mendix expression syntax.

Literals

String Literals

Strings are enclosed in single quotes:

'Hello, world'
'Order #1234'

To include a single quote within a string, double it:

'it''s here'
'Customer''s address'

Important: Do not use backslash escaping (\'). Mendix expression syntax requires doubled single quotes.

Numeric Literals

42          -- Integer
3.14        -- Decimal
-100        -- Negative integer
1.5e10      -- Scientific notation

Boolean Literals

true
false

Empty

The empty literal represents a null/undefined value:

DECLARE $List List of Sales.Order = empty;

IF $Customer = empty THEN
  LOG WARNING 'No customer found';
END IF;

Operators

Arithmetic Operators

OperatorDescriptionExample
+Addition / string concatenation$Price + $Tax
-Subtraction$Total - $Discount
*Multiplication$Quantity * $UnitPrice
divDivision$Total div $Count
modModulo (remainder)$Index mod 2

String concatenation uses +:

SET $FullName = $FirstName + ' ' + $LastName;
LOG INFO 'Processing order: ' + $Order/OrderNumber;

Comparison Operators

OperatorDescriptionExample
=Equal$Status = 'Active'
!=Not equal$Status != 'Closed'
>Greater than$Amount > 1000
<Less than$Count < 10
>=Greater than or equal$Age >= 18
<=Less than or equal$Score <= 100

Logical Operators

OperatorDescriptionExample
ANDLogical AND$IsActive AND $HasEmail
ORLogical OR$IsAdmin OR $IsManager
NOTLogical NOTNOT $IsDeleted

Parentheses control precedence:

IF ($Status = 'Active' OR $Status = 'Pending') AND $Amount > 0 THEN
  -- ...
END IF;

Attribute Access

Access attributes of an object variable with /:

$Order/TotalAmount
$Customer/Email
$Line/Quantity

This is used in conditions, assignments, and expressions:

IF $Order/TotalAmount > 1000 THEN
  SET $Discount = $Order/TotalAmount * 0.1;
END IF;

Date/Time Tokens

Mendix provides built-in date/time tokens enclosed in [% ... %]:

TokenDescription
[%CurrentDateTime%]Current date and time
[%BeginOfCurrentDay%]Start of today (00:00)
[%EndOfCurrentDay%]End of today (23:59:59)
[%BeginOfCurrentWeek%]Start of the current week
[%BeginOfCurrentMonth%]Start of the current month
[%BeginOfCurrentYear%]Start of the current year

Usage in expressions:

$Order = CREATE Sales.Order (
  OrderDate = [%CurrentDateTime%],
  DueDate = [%EndOfCurrentDay%]
);

RETRIEVE $TodayOrders FROM Sales.Order
  WHERE OrderDate > [%BeginOfCurrentDay%];

String Templates

String concatenation with + is the primary way to build dynamic strings:

SET $Message = 'Order ' + $Order/OrderNumber + ' has been ' + $Order/Status;
LOG INFO NODE 'Orders' 'Total: ' + toString($Total) + ' for customer ' + $Customer/Name;

Type Conversion

Use built-in functions for type conversion in expressions:

toString($IntValue)           -- Integer/Decimal/Boolean to String

Enumeration Values

Reference enumeration values with their qualified name:

$Order = CREATE Sales.Order (
  Status = Sales.OrderStatus.Draft
);

IF $Order/Status = Sales.OrderStatus.Confirmed THEN
  -- process confirmed order
END IF;

Alternatively, enumeration values can be referenced as plain strings when the context is unambiguous:

$Order = CREATE Sales.Order (
  Status = 'Draft'
);

Expression Contexts

Expressions appear in several places within microflow activities:

In Conditions (IF, WHILE, WHERE)

IF $Order/TotalAmount > 0 AND $Order/Status != 'Cancelled' THEN ...
WHILE $Counter < $MaxRetries BEGIN ... END WHILE;
RETRIEVE $Active FROM Sales.Order WHERE Status = 'Active';

In Attribute Assignments (CREATE, CHANGE)

$Order = CREATE Sales.Order (
  OrderDate = [%CurrentDateTime%],
  Description = 'Order for ' + $Customer/Name,
  TotalAmount = $Subtotal + $Tax
);

In SET Assignments

SET $Counter = $Counter + 1;
SET $IsEligible = $Customer/Age >= 18 AND $Customer/IsActive;
SET $FullName = $Customer/FirstName + ' ' + $Customer/LastName;

In LOG Messages

LOG INFO 'Processed ' + toString($Count) + ' orders';
LOG ERROR NODE 'Validation' 'Invalid amount: ' + toString($Order/TotalAmount);

In VALIDATION FEEDBACK Messages

VALIDATION FEEDBACK $Customer/Email MESSAGE 'Please provide a valid email address';