Guidance on Automating Role Assignment Based on User Email in Mendix

Hello Mendix Developers,   My team and I are relatively new to Mendix development, and we're currently facing a challenge in our project that we could use some guidance on. We're working on implementing a feature where the system assigns roles to users automatically based on the email they enter during the login process. We've already imported an Excel file containing the necessary email and role mappings into our Mendix application, so retrieving the data isn't an issue. However, as beginners, we're unsure about the best approach to achieve this functionality within Mendix. Specifically, we're wondering: Once we have the user's email, what steps should we take to automatically assign the corresponding role(e.g., students, teachers) during the login process?   We would greatly appreciate any advice, tips, or insights that you can offer. Thank you so much for taking the time to assist us on our Mendix journey!   Best Regards  
1 answers

To assign a role to user you need to set the System.UserRoles association between System.User and System.UserRole. 


So if you have a user's email, you are probably going to have to find the matching Administration.Account by email. Administration.Account is a generalization of System.User. Then look up the matching role. Once you have the two, you should be able to set the UserRoles assocation to grant the user the required role. 


Good luck!