How to retrieve the Records by supplying List of Ids in XPath Constraint

For Example,  I would like to retrieve Employee objects from DB and I have list of Employee Ids.  Now I need to retrieve the Employee objects by supplying the List of Employee Ids in the Xpath constraints. Can anyone help me how to get it done?
3 answers

Hello PREM,

Based on your feedback above (you want to retrieve it in one retrieval activity), the best way I can think of to do this is through a Java action that simply builds the retrieval XPath by iterating over the list of Employee IDs (or receives it as a String parameter) and uses the Java function retrieveXPathQuery (refer to this link for the documentation: ).

Let me know if you require additional help or clarification.


Hello PREM,

If it‘s possible to iterate over the list of IDs that you have then you can just create an empty list of employees before the loop, and then while iterating over the IDs retrieve the employees one by one and add them to the employees list. 

Let me know how does the list of IDs look like if you‘re facing a difficulty iterating over them.


*Edited* Short answer: use OQL. see end of this story for details. *End of Edited*

Only possible in a nasty way:

- create an importmapping that transforms the string into a list of EmployeeId’s

- create a variable for each employeeId via this microflow:

- create the Xpath-contraint to this

 contains(EmployeeID, $Id1) or
 contains(EmployeeID, $Id2) or
 contains(EmployeeID, $Id3)

This is the only way that I can get it done but it would not get past my own peer-review, for one reason: you need to adjust the code to the maximum number of items in the given employeeId-list. Also it will be relatively slow to start with and exponentially slow with greater number of records.

Also, this question shows an example of Mendix being a totally inadequate tool for the job at hand. All the requirement asks is to generate this where:

SELECT id, dateofbirth, socialsecuritynumber, phone, employeename, employeeid, bankaccountnumber
	FROM public."forumquestions$employee"
	WHERE employeeid IN ('001','002');

Hm, can OQL save the day here? … Yes it can! See

And as example, → forumquestions → Question95038. In the string enter a valid list for the where clause without the ( and )