Validate a Boolean attribute

0
Hello Mendix users! I’m new to mendix and i’m working on a task to practice. I have teams and players, and I have a boolean attribute within the player entity called captain, I need to set only one captain per team, how can I do that, so when I choose ‘YES’ It should not allow me to save and to show me an error message. Basically I want it to check if there is already a captain in each team, otherwise I can set a captain.
asked
2 answers
0

Hi Taiseer!

To achieve this, one way is to add an event on change on the boolean field to call a microflow. This microflow should retrieve every member and using a list activity check if there is a player with that attribute as true then you can confirm the new captain or revert the change and show the error message.


If you have any further questions, please let me know!

 

Kind Regards,

Emilio

 

answered
0

Hi Taiseer,

Emilios answer works fine, but please be aware that you will also need to validate behind the save-button if you need a secure system.

https://docs.mendix.com/howto/data-models/setting-up-data-validation#5-advanced-validation-with-a-custom-save-button 

If you don't validate here at the moment you save, it is still technically possible to create two captains in a team.

answered