Facing Error while creating OQL for Dashboard

0
" SELECT DISTINCT TR.RequestID AS RequestID, TR.TripPurpose AS TripPurpose, TR.FromLocation AS FromLocation, TR.ToLocation AS ToLocation, TR.StartDate AS StartDate, TR.EndDate AS EndDate   FROM TravelRequest.TravelRequest AS TR JOIN TR/TravelRequest.TravelRequest_TravelParticipant /TravelRequest.TravelParticipant AS TP JOIN TP/TravelRequest.TravelParticipant_EmployeeInfo /EmployeeInfo.EmployeeInfo AS EI JOIN EI/EmployeeInfo.EmployeeInfo_User /System.User AS U   WHERE U.id = @CurrentUser"  This is my query -  but i am facing error in the last line with all type of parameters - : , [], (), @, $ - I have tried all possible things but not able to solve ,   and if  I am using Xpath so also facing error with   =    "[  TravelRequest_TravelParticipant    /TravelRequest.TravelParticipant    /TravelParticipant_EmployeeInfo    /EmployeeInfo.EmployeeInfo_User    = '[%CurrentUser%]']"   facing error with this part - " /TravelRequest.TravelParticipant   " / this is showing incorrect , please help me out, I am new in the mendix and i am creating travel management system and dashboard. please help me, this is my first project.
asked
2 answers
0

Hi Umme,

The issue is primarily related to how Mendix handles the current user and the correct usage of associations in OQL and XPath.

OQL – @CurrentUser is not supported

In Mendix OQL, @CurrentUser cannot be used directly in the WHERE clause. OQL only supports parameters, which must be passed to the query through the data source configuration. Using @CurrentUser directly will therefore result in an error.

Correct approach in OQL

Instead, you should define an OQL parameter and pass the current user as an object parameter to the query. This can be done using the Java action provided by OQL to add an object parameter, and then reference that parameter in the WHERE clause.

image.png

This approach is the supported and recommended way to use parameters in OQL.

you can also find the example usage of this action under the Examples in the OQL Module

image.png

Example Scenario:

image.png

answered
0

In Mendix OQL, @ cannot be used for parameters because OQL does not support SQL-style variable notation; instead, it only supports named parameters defined with $. Parameters must be written as $ParameterName. This is why WHERE U.id = @CurrentUser causes an error, while WHERE U.id = $CurrentUser is the correct and supported approach in Mendix OQL. Before the execution activity, please use "Add object parameter" activity like below:

 

Screenshot 2025-12-23 at 09.41.06.png

answered