Add a new entity to your module. This new entity will contain all the extended attributes you might want to save for the User. In this sample I named it UserExtended. We should expose the entity as Public so we can reference it from other modules. If you need more information about allowing or not cascading deletes from a public entity, check this link.
Now we need to correctly define the Primary key of this new entity. We want this new entity to have a 1 to 1 relationship with the User entity. To accomplish this, we need to set the primary key as the UserId. To do this, simply change the automatically added Id attribute to UserId, and the development environment will do the rest. Notice how the data type was automatically changed to User Identifier
By now, you should have something similar to this:
In this sample I have two new attributes to the User Entity: CountryId, and Interests. The goal is to capture information of the Country where the User lives, and what are his interests. Note that all existing mechanisms of the platform are available and I can easily extend this entity with, for example, other associations. In this case, Interests could be its own Entity.
Now, we just need to use the new entity. Instead of fetching data from the User entity alone, we join this entity with our UserExtended entity, now having all the attributes from both the User entity and UserExtended entity.
Here is how a simple query to fetch User data should look like:
To Create or Update a User to the database, we now need to interact with two entities. The order by which the CreateOrUpdate actions are run is important, as we need to set the correct UserId for the UserExtended entity. To do this, first run the action to CreateOrUpdate the User entity, set the UserId of the UserExtended entity to the Id returned from the CreateOrUpdateUser action, and run the CreateOrUpdate action for the UserExtended entity.
A Save action for a UserExtended should look something like this:
And this is it. Pretty simple right?
Check the attached file with the application used in this post. A live demo is available at http://joaobatista.outsystemscloud.com/UserExtension/
Feel free to ask questions or give suggestions.