| title | Static Entity Alternatives |
|---|
A computing best practice is not to use literals in your code. This is known as hard-coding and it makes it harder to maintain your code.
The default method to store a list of values in OutSystems is to use a Static Entity. The drawback of using static entities is that each static entity counts for an Application Object (AO). Since most licenses include a limited amount of AO's consider one of the alternatives to avoid using AO's for static entities.
This article describes the following alternatives:
For a single value you can just define a local variable and give it a default value. To emphasize its constant behavior you can prefix these local variables with Constant. E.g. ConstantMaxRecords
When a literal is used multiple times you can create a Function Server Action that returns the fixed value. This may be useful for configuration values etc. Also here prefixing the name with Constant is used. E.g. ConstantDefaultPageSize.
Please note: When it's required to be able to change these values at runtime you should use site properties in O11 or Settings in ODC.
When you require a record list you can import a JSON file and convert it to a structure list.
We provide a JSON with the id and the name of the weekdays.
[
{"id": 1,"name": "Monday"},
{"id": 2,"name": "Tuesday"},
{"id": 3,"name": "Wednesday"},
{"id": 4,"name": "Thursday"},
{"id": 5,"name": "Friday"},
{"id": 6,"name": "Saturday"},
{"id": 7,"name": "Sunday"}
]- In Service Studio we create a structure from json

- Which gives us a weekday structure that we will use in our logic.
- Now import the json file in the resources folder.
Server Action WeekDayGet:
- In the logic tab we create a new folder "Weekday" in the server actions folder
- In this folder we create a new server action "WeekdayGet"" with output parameter "Weekdays"
- To improve performance set the property "Cache in minutes" a value e.g. 120
- Add a "BinaryToText" action to the logic, set parameter binary data to "Resources.weekdays_json.Content"
- Add a "JSONDeserialize" to convert the json to a weekday list
- Add a an "assign" to add the converted list to the output list
Server Action Function WeekdayGetById:
- Create a Server Action WeekdayGetById in the folder Weekday
- Add an input parameter WeekdayId, type integer
- Add an output parameter Weekday, type Weekday
- In the action flow add a server action WeekdayGet
- Add a ListFilter to filter the Weekday List on WeekDayId
- Raise an Exception if the day is not found
- Assign the found weekday from the list to the output parameter
As an alternative we can import and convert an Excel file.
Given an Excel file Categories with columns Name, Slug and Description we can create a Category structure and CategoryGet and CategoryGetBySlug functions.
- In the Data tab import the "Categories.xlsx" file
- Create a new structure "Category" with attributes:
- Name
- Slug
- Description
- Create a server action CategoryGet with output parameter Categories
- Add an ExcelToRecordList action to the action flow
- Record definition: Category
- File content: Resources.Categories_xlsx.Content
- Assign the ExcelToRecordList1 to Categories
Although the solutions above avoid consuming AO's it add extra complexity to your code. Extra logic is required for the following use cases:
- Joining in aggregates and sql queries
- Applying translations
- Multi-tenancy
In addition there can be a significant performance impact.
Therefore, make a careful consideration before choosing a static entity or one of the alternatives.
*[AO]: Application Object *[O11]: OutSystems 11 *[ODC]: OutSystems Developer Cloud





