I've had too many times a situation where I find myself with a string value and have to find a corresponding enumeration value for it. Mostly in data transport situations between various systems.
So I was wondering: if we can have 'getCaption' and 'getKey' for enumeration values, would it not be helpful to also have at least a 'findByKey' for enumeration values (I can understand 'findByCaption' would be challenging in multi-lingual apps)
Hi Ronald,
Have a look at my Marketplace contribution Convent Commons
It has beside other things a lot of functionality about enums.
P.E. in answer on your request for findbykey:
Enum Mutation Functions
NameToEnum
ObjectToChange - MxObjectAttributeName - as stringValueAsString - Key/Name as stringCaptionToEnum
ObjectToChange - MxObjectEnumName - Full enum name (module.enumname like system.language)AttributeName - as stringValueAsString - Caption as string
Note: For the Enum Mutation Functions it is necessary to make a copy of the template function. In the copied function you need to replace the placeholder entity (MxObject System.User) with the entity that has the enum to change as an attribute. This is because the Mendix Modeler cannot handle abstract entities, but wants an explicit entity.
I agree, it would be useful to have an option in Mendix to convert a string into an enumeration value.
Currently you can achieve this through a Java Action EnumerationFromString in Community Commons, but built-in would be better =)
I think this is the same idea as
https://community.mendix.com/link/space/studio-pro/ideas/306
https://community.mendix.com/link/space/studio-pro/ideas/2079