To use a microflow I think is no option. Than I have the same problem as before that I must create a validation message for every attribute again.
So I try to use the method "addDatavalidationFeedback" in the java action. But only adding it doesn't to anything. Someone know how to use it?
See the addDatavalidationFeedback items in the core action API
Providing the MendixIdentfier of the object (should probably the same as on which the original microflow was invoked) and a HashMap of field -> error should do the trick. If it doesn't, can you describe the whole flow?
You can at least invoke a microflow from a java action that does the message or throw an exception with a descriptive message but you have to handle that in the java action call. The disadvantage that your flow is stopped.
I call the action:
CheckFilledAttributeOfObject(IMendixObject MendixEntityParameter1, String MendixAttributeParameter1)
out of the microflow with the entity and the attribute name to validate.
In the action I a helper action:
public static boolean CheckFilledAttributeOfObject(IContext context, UserAction action, IMendixObject MendixEntityParameter1, String MendixAttributeParameter1) { String attributeValue = String.valueOf(MendixEntityParameter1.getMember(context, MendixAttributeParameter1).getOriginalValue(context)); if(attributeValue.matches("") || attributeValue == null || attributeValue.matches("null")) { Map<string,string> members = new HashMap<string,string>(); members.put(MendixAttributeParameter1, MendixAttributeParameter1 + "must be filled"); action.addDatavalidationFeedback(MendixEntityParameter1.getId(), members); return false; } else { return true; } }
So I think I do not use the "addDatavalidationFeedback" in the right way?
The following code snipped will do the trick.
Java Action with 3 parameter:
Message (String)
// BEGIN USER CODE
IContext context = this.getContext();
String attributeValue = String.valueOf(this.ObjectToCheck.getMember(context, this.AttributeName).getOriginalValue(context));
Core.getLogger("CheckField").info("Member"+this.AttributeName +":"+attributeValue);
if(attributeValue.matches("") || attributeValue == null || attributeValue.matches("null")) {
Map<String,String> members = new HashMap<String,String>();
members.put(this.AttributeName, this.Message);
this.addDatavalidationFeedback(this.ObjectToCheck.getId(), members);
return false;
}
else {
return true;
}
// END USER CODE