IsValid flag is not needed in validation microflows

0
Mendix docs suggest that when you use the "Validation Feedback" activity you also change the IsValid variable to false and at the end if it's false you halt the save operation. The "Generate validation microflow..." menu item does the same. But did you know that this small java action can do the same and even more? // BEGIN USER CODE // ThrowValidationsAsUserException final var it = getContext().getDataValidationList().iterator(); if (it.hasNext()) { // The UI will show all invalid objects despite throwing only the first one throw new UserException(it.next()); } return null; // END USER CODE If you put it to the end of a validation microflow it will halt the save operation without logging the error and show the validations on the UI. Benefits: fewer activities Never worry that you forgot to check the value of $IsValid, especially in sub-microflows Works inside "before commit" entity event, even when saving lists of objects
asked
1 answers
1

Thats correct and a nice idea, but you loose some advantage of mendix. You loose readability for extra code, which does not have some much of an advantage. From my point of view, be carful with custom code.

answered