Getting all enum elements

0
Hi, is there a possibility to flatten an enum type as json string? I am wanting to define a REST API Endpoint to query all possible enum values (name and key)   Thanks, Ingo  
asked
2 answers
3

Include the module in model reflection and pull the enum values from the database

Edit: After model reflection has done its magic, you have a normal database at your disposal containing information about your entities and attributes. For each enum attribute it will have all enum values and their captions.

Just follow the installation instruction in the appstore module, tick the checkbox for the module that contains an entity with an attribute that has the enum as its type. When you then click the button to update, it will update the database with information about your entities, which includes the enum values of your enum. Browse your entity in the model reflection page and you will see your enum values.

In a microflow, you will need to retrieve the MxObjectEnumValue objects that belong to your attribute. To prevent hardcoding this into the microflow, I usually put the association to the right reflection object on some configuration entity I create myself. In your case, you need to find the right MxObjectEnum and retrieve all MxObjectEnumValue objects that belong to it. If you need captions, also retrieve MxObjectEnumCaptions

answered
1

With some java code this should be possible.

Have a look here to see how toi iterate over an enum: https://www.baeldung.com/java-enum-iteration

Then you could build the json in the code or create a NPE with the values and expose that in the API.

answered