OutSystems allows you to store the application state and use it throughout end-user navigation across screens. For example, when navigating to a screen, render it based on the state you left it.
In web applications, a session is created in the first request an end-user makes to the server. You can use <icon> Session Variables to store the application state:
Open the Data tab of your module and create a Session Variable;
In the action flow, assign the values you need to keep in the session variable;
When you need to use the state data, get it from the session variable as you would with any other variable.
In mobile apps, the state of a screen is automatically restored when navigating back to it. To implement other functionality than that, you can use the local storage to save and use the application state.
In the GoOutWeb web application, for finding, reviewing and rating places, the Places screen allows end-users to search for places. The search criteria is saved in SearchKeyword, a local variable of the screen. Once we navigate to another screen, the search criteria is lost. What we want is to keep that search criteria when getting back to the Places screen. For that, we have to store the search criteria in a Session Variable, instead of a Local Variable.
To create and use a Session Variable:
Go to the Data tab and create a Session Variable of type Text, and name it Places_SearchKeyword;
On the Places screen, select the search input widget and replace the local variable with the created session variable;
In the Preparation action, open the GetPlaces aggregate, and change the Filter to use the session variable instead of the local variable:
Place.Name like "%" + Session.Places_SearchKeyword + "%" or
Category.Label like "%" + Session.Places_SearchKeyword + "%"
Delete the SearchKeyword local variable. Check the errors and replace the local variable by the session variable;
- Publish and test.