How to extend the User entity to capture additional attributes

Sometimes we need to capture more information about a User, like the country of origin, interests, weight, height, etc. Because the User entity is already built into the platform, a common question from many developers is how to add attributes to it. Although you can’t add attributes directly to the User entity, extending it is quite simple. In this How-to, I will try to explain how simple it is to achieve this in OutSystems Platform.

Step 1 - Create the extended entity

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.

Step 2 - Define the primary key

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.

Step 3 - Query the new 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:

Step 4 - Write to the new entity

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

Feel free to ask questions or give suggestions.

Great info João!

Let me just add to this that you can watch the following lesson on the online training: Create and Display One-to-One Relationships