1Constrain Your Data Using XPath
Essential
Learning goalRetrieve the correct objects and apply data-level access restrictions.
Key notes
- XPath constrains objects retrieved from the database. It is not general-purpose SQL; it uses Mendix entity, attribute, association, and system-variable concepts.
- Attribute constraint filters by an attribute:
[Status = 'Open']. - Multiple bracketed constraints combine as AND:
[Status = 'Open'][Priority > 2]. Useorwhen either may match; use parentheses to make combined logic clear. - Association constraint filters through a relationship:
[Order_Customer = $Customer]. The association name and direction must match the model. - Use variables to compare against a current object or parameter. A variable such as
$Customeris not interchangeable with a system variable. - System variables include
[%CurrentUser%]and[%CurrentDateTime%]for dynamic constraints. - Enumeration constraints must use the correct qualified enumeration value, not arbitrary display text.
- String functions such as
containsorstarts-withsupport text constraints. Watch case sensitivity and exact syntax for your Mendix version. - XPath is used in data source retrieves and entity access rules. Access-rule constraints limit which records a role can read or modify.
- Filtering in a page widget is not a security boundary. Enforce security server-side with entity access and microflow permissions.
- Constrain data as close to retrieval as possible; do not retrieve large lists and filter them later.
Worked scenarios
- Library: My_Borrowings shows only the logged-in borrower's records. The record must relate to the Borrower account tied to the current user. Apply an access rule or secure retrieve condition, not only a page filter.
- Future events: retrieve records related to a selected Course whose StartDate is later than the current date/time. Confirm the association path and the date comparison.
- Empty retrieve: inspect the exact attribute, association direction, variable value, date boundary, and access rules. Test with known sample data.
Be able to answer in the exam
- Difference between an attribute constraint and an association constraint.
- Interpret AND/OR combinations and predict which records match.
- Choose between a literal, a microflow variable, and a system variable.
- Why page filtering does not replace entity access rules.
- How an XPath access rule restricts a user to their own records.
Common misconceptionDo not assume a page filter protects data. A user may reach the data through another page, microflow, or integration unless server-side permissions are configured.
BonusExtra for the exam
- Fully qualified names:
[Module.Order_Customer = $Customer]and across associations[Module.Order_Customer/Module.Customer/Name = 'Ann']. - Empty checks:
[Attr = empty],[Module.Assoc = empty],[Module.Assoc != empty]. - Tokens go in quotes:
[StartDate > '[%CurrentDateTime%]'],[System.owner = '[%CurrentUser%]']. Day/week/month/year helpers exist, e.g.[%BeginOfCurrentDay%]and[%EndOfCurrentDay%]. - Microflow variable vs page token: in a microflow retrieve you write
$Customer(no quotes). In a page widget XPath you cannot use microflow variables; use[%CurrentObject%]for the context object. - Other functions:
not(...),contains(Name,'abc'),starts-with(Name,'A'). Keywordsand/orare lowercase. - A user with several module roles gets the union of their entity access rules (rights add up).
- Retrieve with XPath runs in the database. Retrieve everything and then Filter list in memory is slower and usually the wrong answer.