Add a microflow function to find an enumeration value by key. - Mendix Forum

Add a microflow function to find an enumeration value by key.

6

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)

asked
2 answers

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

  • Parameters:
    • ObjectToChange - MxObject
    • AttributeName - as string
    • ValueAsString - Key/Name as string
  • Result: Attribute in Object receives the enum value corresponding to Value

CaptionToEnum

  • Parameters:
    • ObjectToChange - MxObject
    • EnumName - Full enum name (module.enumname like system.language)
    • AttributeName - as string
    • ValueAsString - Caption as string
  • Result: Attribute in Object receives the enum value corresponding to Value

 

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.

 

Created

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

Created