Perhaps I don't understand what you are trying to do, but to get the label of an enumeration value, you could use the following code (where inboekingStatus is an enumeration and language is a System.Language object):
// BEGIN USER CODE
return inboekingStatus.getCaption(language.getCode());
// END USER CODE
Your code is already achieving what you desire. I would however change your enum class parameter from string to an enum that contains all possible enums that you want to pass to this JavaAction, so that typing mistakes can't occur and future refactoring is easy. Example:
Then your code already works (abridged version):
String enumerationParam = "mymodule_proxies_myenum"; //Example of first parameter
//caption will be mymodule.proxies.myenum
String localeParam = "en_US";
Class<?> clazzMendixEnum = Class.forName(campaign.proxies.Enumerations.valueof(enumerationParam));
Field mendixField;
for (Field field : clazzMendixEnum.getDeclaredFields()) {
field.setAccessible(true);
if (field.getName().equalsIgnoreCase("String")) {
mendixField = field;
Method m = clazzMendixEnum.getMethod("getCaption", String.class);
m.setAccessible(true);
// Return locale version of enum caption
return (String)m.invoke(mendixField.get(null), localeParam);
}
}
return null;
Ideally though, Mendix should provide this as a first-rate microflow expression function, similar to getCaption but with a locale as a second argument.