Creating a data model in OutSystems 11

Ricardo Pereira
5 min readAug 7, 2023

--

This article will focus on developing a data model that supports an application. We’ll be learning about creating Entities and setting up relations between them to support an application (and don’t forget, this is just an example).

To better understand how all this works, there is nothing better than practicing. Let’s play with the concept of an Help Desk application!

  1. We need to start by creating a data model inside our new module (preferably a module of type Service):

1.1 — Click on the Data tab, then right-click on Database and select Add Entity:

Fig 1 — Adding an Entity to the database

1.2 — Name the Entity Ticket. Then, right-click and select the Add Entity

attribute option. Name this new attribute Description:

Fig 2 — Creating an attribute on an Entity

1.3 — Now, we right-click on Database and select Add Static Entity. Name the new Static Entity Status:

Fig 3 — Adding a Static Entity to a database

1.4 — Expand the newly created Status Static Entity, right-click on the Records folder, and select the Add Record option. Name it New. Repeat the process of adding records to create the Open, Discarded, and Closed records:

Fig 4 — Creating a record on a Static Entity

The new Static Entity should look like this:

Fig 5 — Status Static Entity with records view

1.5 — The next step is to use the same technique for creating a new Static Entity but for AffectedAreas. This Entity must have the Commercial, HumanResources, Factory, and Financial records. In the end, the Entity must have the following structure:

Fig. 6 — AffectedAreas Static Entity with records view

NOTE: The label that is shown later can be edited directly in the record. To do this, we just click on the record in question, go to the properties, and customize the label’s value. This can be very useful to make the value more human-readable.

1.6 — Now, we are going to create an auxiliary Entity that allows us to implement a many-to-many relationship between the tickets and the affected areas. To do this, right-click on Database again and select Add Entity. Name this Entity AffectedAreasByTicket. Next, drag and drop the Ticket Entity on top of the newly created Entity. Do the same with the AffectedAreas Entity. We will see that Service Studio automatically creates the foreign keys for these two Entities in our new Entity, thus making the many-to-many relationship:

Fig 7 — Affected areas by ticket auxiliary Entity with their foreign keys

1.7 — Both foreign keys must be mandatory. To do this, click on the attributes sequentially and change the Is Mandatory parameter to true in the properties section, looking like this:

Fig 8 — Foreign key properties and focus on the Is Mandatory attribute

1.8 — The next step is to add the missing attributes to the Ticket Entity. Foreign keys relating to the Status, CreatedBy, and UpdatedBy attributes can be created by simply dragging the Entity to be related on top of the Ticket Entity, but let’s see another way to do it. Let’s create the StatusId, CreatedBy, and UpdatedBy attributes, as explained in the previous steps for creating attributes in Entities.

Let’s confirm that the platform automatically inferred the attribute types for the intended foreign keys:

Fig 9 — Foreign keys in the Ticket Entity with Is Mandatory set to No

NOTE: The platform infers the attribute type based on the name we give it. If we want something more personalized and the platform cannot infer the correct type, clicking on the attribute, in the same properties box, we can change the type in the Data Type dropdown.

1.9 — Now we must make these three new attributes mandatory using the method explained in the previous steps. It should look like this:

Fig 10 — Foreign keys in the Ticket Entity with Is Mandatory set to Yes

1.10 — Finally, let’s create the last two attributes needed for this phase: CreatedOn and UpdatedOn. Right-click on the Ticket Entity and select Add Entity Attribute for each one of them. In the properties section of each of these attributes, we must set the Is Mandatory parameter to Yes. It should look like this:

Fig 11 — Ticket Entity with attributes to audit updates

NOTE: In the section with the properties of Entities and their attributes, there is a parameter called Description. Here, we can write a brief explanation of the concept of the respective Entity or attribute. With this, we facilitate future interpretations of the implementation of our applications.

2 — Now, we need to create our data model inside our Entity diagram:

2.1 — In order to have an overview of how our Entities are related, we can create a diagram of the data model. To do this, right-click on the Diagrams folder in the Data tab and select the Add Entity Diagram option. Name it HelpdeskDiagram:

Fig 12 — Add Entity Diagram in Service Studio

2.2 — To finish the diagram, we drag and drop all the necessary Entities to the canvas. The end result will be the visualization of Entities and their relationships in our data model:

Fig 13 — Entity diagram view in Service Studio

2.3 — Finally, just click on the Publish button and our module is compiled and saved in our environment:

Fig 14 — Publishing new developments in Service Studio

Graphically, the representation of the various components of Entities are numbered in Fig 14 as follows:

1. Static Entity symbol

2. Entity symbol

3. Symbol of a regular attribute (not primary or foreign key)

4. Primary key symbol

5. Foreign key symbol

With this example, we understood how to create our Entities and how to set up relations between them in order to store all the necessary information efficiently.

Although simple, we have an efficient data model capable of supporting the needs of our application. All this is done in just minutes, fantastic, isn’t it?

--

--

Ricardo Pereira
Ricardo Pereira

Written by Ricardo Pereira

Passionate about software development, started my journey in Outsystems in 2016, getting completely addicted to the platform.

No responses yet