Skip to main content

Developing an Application

 

OutSystems

Create a Calculated Attribute in an Aggregate

There are situations when the data fetched from the database isn’t enough and you need to add more information to each record, namely based on the values returned. OutSystems allows you to do it. You can add new attributes to the records returned by the aggregate based on the value of the other attributes:

  1. In the aggregate, click on New Attribute to add a new attribute to the aggregate and name it;
  2. Open the attribute menu and select Edit formula...;
  3. Define the expression to calculate the value.

Example

In the GoOutWeb, a web application to check interesting places, we have a screen to list places. In this screen, we want to allow the end-user to filter the listed places by category selecting an available category from a Combo Box. Additionally, in each entry of the Combo Box we want to display the number of places that have that specific category along to the category name.

To calculate this data and add it to each entry of the Combo Box:

  1. Since this is a web application, add an aggregate to the screen’s preparation;
  2. Add the Place entity to it;
  3. In the aggregate, do the following:
    1. Group by Category.Id;
    2. Count by Place.Id to have the number of places per each category;
    3. Group by Category.Label to get the label of each category;
    4. Open the last grouped column menu and add a new attribute. Name it “Combo Box Label”;
    5. Assign the following expression to the created column:
      If ( Label <> "", Label + " (" + Count + ")" , "Not categorized" + " (" + Count + ")" )
      where Label and Count variables are two of the previously grouped columns.

  4. Go to the screen and add a Combo Box. Set its values to be the returning list of the new aggregate.