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

1
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?
asked
3 answers
2

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: https://apidocs.mendix.com/7/runtime/com/mendix/core/Core.html ).

Let me know if you require additional help or clarification.

answered
0

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.

answered
0

*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:

https://modelshare.mendix.com/models/047ab816-53a1-4cd9-9560-914532a6ccfe/sub-employee-get-by-array-of-employee-id
 

- 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 https://modelshare.mendix.com/models/f81b285f-bd8f-4f63-8322-3ff5b19a2b1f/sub-employee-get-by-array-of-employee-id

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

 

answered