In Part 3 of the OQL Series, learn how to use parameters in OQL queries within Mendix to make your queries more dynamic and flexible. Discover how to pass values into your queries for filtering, sorting, and refining results based on user input or application logic
Dependencies: -
install this module from Mendix marketplace.
OQL Series Part 1: Introduction to Object Query Language in Mendix

Right click on MyFirstModule or YourModuleName(OQL_Series) -> Add Other -> Data Set -> give any name(OQL_Parameters) & Click Ok.

Open your OQL_Parameters data set by double clicking and write the below OQL statement
SELECT
BookName as BookN,
Price as BookPrice,
OQL_Series.Book/OQL_Series.Book_BookAuthor/OQL_Series.BookAuthor/AuthorName AS BookAuthorName
from OQL_Series.Book where Price>=$Value1 and Price<=$Value2

Add two Integer/Long parameters & keep uncheck the isRange.
You can add any parameter(Boolean, String, Integer/Long, Decimal, Date and time, Enumeration, Object) but for this tutorial i am using Integer/Long parameters.

IMPORTANT :- BookName , Price & AuthorName are the persistable entity attribute name please give the same name which are available in the entity, OQL_Series is the module name & by using a dot(.) you can select your entity.
Whenever you use “as” keyword(BookName as BookN) you have to make a Non persistable entity to return & please keep the NPE attribute name same as which you are using after “as” keyword(BookN).
Whenever you are working with association you have to use “as” keyword(BookName as BookN) & need to make NPE to return, without “as” keyword you are not able to write the OQL Query.
MICROFLOW LOGIC TO EXECUTE OQL:-
Make a microflow to execute the OQL, Right click on OQL_Series -> add microflow -> give the name DS_BookWithParameters.
Go to microflow :-
- Create 2 Integer/Long parameters as you want or give dynamic value according to your requirements.I am giving static value for $Value1(40) & $Value2(90).
2. In the microflow search Add integer long value & take 2 integer long value activity and please give the same name which you used in the OQL statement.



3. Drag the Execute OQL Statement activity & Configure the value And return the List(If you want to show the data on a page).

Now run the application & test it.

In the parameters, we passed Value1 (40) and Value2 (90) and constrained the Price value using ≥ and ≤. That’s why we are getting results with prices between 40 and 90.
Conclusion:
I hope this article has helped you understand How we can use OQL parameters in Mendix.
Thanks for reading this! See you in the next blog post.