Retrieving the Current User with a Microflow
Introduction
In order to implement a certain logic, you often need to identify the user who is currently logged in. The following are facts about user management in a Mendix app:
- The currently logged-in user is always available in microflow calls and XPath constraints, and it can be retrieved in a microflow for subsequent querying or manipulation.
- All application users/accounts are a specialization of
System.User
, and very often and by default, it isAdministration.Account
. - In Studio Pro, the Administration module is added by default. It allows you to manage local accounts and view app statistics.
This document teaches you how to do the following:
- Retrieve the currently logged-in user in a microflow using the Account entity from the Administration module in Mendix
Prerequisites
Before you continue, make sure you have completed the following:
- Install the latest version of Studio Pro
- Read about the Administration module in the Studio Pro Guide
- Understand the basics about microflows
Retrieving the Current User
To retrieve the currently logged-in user using the Account entity from the Administration module, do the following:
-
Open an existing microflow or create a new one.
-
Navigate to the Toolbox and search for the Retrieve activity.
-
Drag the Retrieve activity into your microflow.
-
Double-click the Retrieve activity to open its properties.
-
Choose From database as the Source.
-
Click Select… for Entity.
-
In the Select Entity dialog box, go to Marketplace modules > Administration, and select Account.
-
Choose First as the Range. This is because what you are looking for is the currently logged-in user, which is always only one object.
-
In the XPath Constraint box, type in
[id = $currentUser]
and click OK.For Mendix version 10.5 and above, click Edit… next to XPath constraint to open a dialog box where you can enter your constraint in XPath expression mode.
Now you have the microflow that retrieves the current user!