In the periods of yore, we great pioneers of Mendix waded deep into the murky depth of the modeler handling web service mappings after web service mappings. From these times came an enumeration mapper of inspired thought: Keeping Enumerations as Entities
As you can see from this article it allowed us to get away from pesky manual comparison microflows of strings to enumerations. Unfortunately this methodology has its drawbacks, first of all the enumerations were stored in the database which implies constant database queries when mapping. Now if we could only get away from this…
Well good news! today we have come with more gifts for you intrepid modelers: An alternate method for determining an enumeration from a string.
So how do we do it. Well firstly lets look at the problem, we have a few situations (xml, webservices) where we can receive a string we need to map into an enumeration. So what we are looking for is a method to input the string and retrieve the enumeration value. Now java actions and microflows only return specific enumerations, so unfortunately we cannot get away from this. However we can make an easy way to retrieve this.
So in the new method we create a non persistent entity we call “EnumerationMap”, to which we add the enumerations we wish to map.
The ext step is to create a java action which given a name for the enumeration and its value (caption or value but case sensative) can return the EnumerationMap entity populated with the found value. We can then build a nice and simple microflow which returns the enumeration as required (see below). and voila, now only one annoying entity(although non persistent) in the model and no db queries required.
To see the magic sauce inside the java action please download the example project package here (v 4.0.1)
Please let me know if there are any thoughts or queries