For a pretty flexible solution you could pass 3 strings, one as the name of the entity containing the enumeration and the other the actual enumeration attribute name and last the microflow name.
String 1 EntityContainingEnumAttribute format 'ModuleName.EntityName'
String 2 EnumerationAttributeName format 'AttributeName'
String 3 MicroflowToExecute format 'ModuleName.MicroflowName'
IMetaObject metaEntity = Core.getMetaObject(EntityContainingEnumAttribute);
IMetaPrimitive primitive = metaEntity.getMetaPrimitive(EnumerationAttributeName);
IMetaEnumeration metaEnum = primitive.getEnumeration();
// In case the attribute name passed was not an enumeration
if(metaEnum == null)
throw new MendixRuntimeException("'" + EnumerationAttributeName + "' is not an enumeration type.");
Map<String, IMetaEnumValue> enumValues = metaEnum.getEnumValues();
for(String key : enumValues.keySet()) {
//Execute MicroflowToExecute for each key in enum.
//Didn't include this because perhaps you want to run the microflows async or whatever.
}
Rom, you could do the following:
Pass only the name of the microflow. As long as this microflow has only an enum as parameter, you can easily determine what enum this is in your Java action (by looking the microflow up in the Microflows generated Java class) and then call the microflow for every value of the enum.
It seems to me this achieves what you are trying to achieve.
Proxies are available for that purpose and can easily create conversion java-actions like
try {
MyEnum rt = MyEnum.valueOf(value);
return rt.toString();
} catch (Exception e) {
return null;
}
I could not find a way to get to an enum directly, however, Java interface IMetaObject can return the enum type. Maybe this is a nice new feature for MxModelReflection? The enum values are already processed, but the enum name itself not.
Maybe too late, but I needed exactly the same Java action.
This worked for me:
public java.lang.Void executeAction() throws Exception
{
// BEGIN USER CODE
var positionDot = EnumFullName.indexOf(".");
var namespace = EnumFullName.substring(0, positionDot).toLowerCase();
var classNameWithoutNameSpace = EnumFullName.substring(positionDot + 1);
var fullClassName = namespace + ".proxies." + classNameWithoutNameSpace;
var enumClass = Class.forName(fullClassName);
var context = Core.createSystemContext();
for (var enumName : enumClass.getEnumConstants()) {
Core.microflowCall(Microflow)
.inTransaction(true)
.withParam(classNameWithoutNameSpace, enumName.toString())
.execute(context);
}
return null;
// END USER CODE
}
Use for example:
EnumFullName: "CommunityCommons.LogLevel"
In the Microflow create 1 input parameter with exactly the name of the Enum without namespace (LogLevel).
Good luck.