How to use HashMap feature in Mendix.

Hello Team, My requirement is to use key pair value where the key will be an employee ID and the Value will be the Employee Object. I want to implement the HashMap feature or LinkedHashMap Feature for this scenario. Please suggest me how to achieve this feature in Mendix.   Thanks, Ankit
2 answers
There is no HashMap in Mendix. The only option is to use a java action and implement the hashmap in java.



With this sollution you could do it with XPath but you need an Enddate for the XPATH. First add the Enddate attribute to the objects you are retrieving. Then create a hotfix microflow to fill the enddates. This hotfix microflow should use limit and offset to iterate over all the objects. For every employee retrieve all the objects and let the list sort on the effective date descending. This way the first object in your list is the last object for that employee. Since it is the last you can leave the enddate to empty. Store the effective date in a local variable so you can use that one in the next iteration and store it in the enddate. Double check after running the hotfix that all objects have a correctly filled enddate. Now you can create the XPath that retrieves only the right object of the effective period. It will look something like this

[effectiveDate <= [%BeginOfCurrentDay%] and (endDate >= [%BeginOfCurrentDay%] or endDate = empty())]

Note that you should use BeginOfCurrentDayUTC if you do not use timezones and that you only should retrieve the first. This way you never retrieve objects in the future because effectiveDate is after the current day and since all the older records have an endDate that is before the current date you also do not retrieve those records.
Hope this helps,