OutSystems allows creating variables that are stored and changed at the environment level. They are normally used to implement application behaviors that are configurable at runtime. And remove the need of redeploying the application. These variables are known as Site Properties.
When a Site Property is created, it is set by the developer with a default value. At runtime, someone with privileges can change its value through the environment management console.
To create and use a Site Property, do as follows:
- In the Data tab, right-click on the Site Properties folder, and add a site property;
- Define the name, data type, and its default value;
- Use in your code by referring to it as Site.<SitePropertyName>.
In a mobile application, a Site Property can only be used:
- Go to the web application:
Create an action that returns the site property value. Expose the action to reuse it in the mobile application.
- Go to the mobile application:
Add a dependency to the action created in the web application;
Implement the logic that needs the value of the site property.
Example in a Web Application
The GoOutWeb is a web application for finding, reviewing, and rating places. It also allows reporting reviews as inappropriate. Now, we want to block the access to the application to end-users who exceed a number of reviews reported and confirmed as inappropriate.
At the start, the limit is three, but we want to be able to adjust it in time without having to redeploy the application.
We have to create a Site Property and use it to check the limit of confirmed reports per end-user:
- In the Data tab, right-click on the Site Properties folder to add the site property:
- Name it MaxReportedReviews;
- Set its data type to Integer;
- Set the default value to 3.
- Go to the ReportedReviews screen and open the Confirm screen action;
- After updating the review as inactive, add an Aggregate to count inactive reviews with reports per end-user;
- Iterate the aggregate results and:
- Check if the count exceeds Site.MaxReportedReviews;
- If True, put the end-user as inactive.
- Publish and test.
Example in a Mobile Application
The GoOutWeb web application has a configuration (in a Site Property) for minimum length a comment must have in reviews. We want to have this same behavior in reviews entered in the GoOut mobile application.
Go to the web application:
Create an action called SiteProperty_MinimumCommentLength that returns the value of the Site.MinimumCommentLength site property;
Expose the action and publish the application.
Go to the mobile application:
Add a dependency to the SiteProperty_MinimumCommentLength action;
Go to the WriteReview screen and, in the Save client action:
Call the SiteProperty_MinimumCommentLength action to get the site property value;
Implement the logic to validate the size of the comment.
Publish and test.