In OutSystems, to promote reusability and abstraction you can create actions and later invoke them in other action flows. This allows you to centralize the logic and makes it easier to maintain. For example, you change it in only one place and everyone using it will benefit.
To encapsulate logic in an action:
- In the Logic tab, create a Client or Server action, depending on if you want to execute this logic in the device or in the server;
- Implement the logic in the action flow.
To use the encapsulated logic in another action:
- Open that action’s flow;
- Drag the action with the encapsulated logic from the Logic tab and drop it in the flow;
- Set the values of the input and output parameters, if any.
In GoOutWeb, an application for finding and reviewing places, we can create or update a Place by using the CreateOrUpdatePlace entity action. However, we want to be sure a place is valid before creating or updating it in the database. In that way, we want to create an action that validates a Place before and, if valid, stores it in the database. This action will be used in all situations where we want to create or update a Place.
To create the action:
- Go to the Logic tab , right-click on the Server Actions folder, and add the new server action. Name it
- Add the following input parameter:
Placeof type Place.
- Add the following output parameters:
PlaceIdof type Place Identifier;
ErrorMessageof type Text;
Successof type Boolean (set the default to
- Implement the logic:
- Validate that the Name and Address attributes are not empty;
- Execute CreateOrUpdatePlace and assign the Id to the output parameter PlaceId.
To use this action in the creation or update of places in the GoOutWeb application:
- In the Interface tab, find the PlaceEdit screen, and open the Save screen action;
- Drag the Place_CreateOrUpdate action from the logic tab to the action flow;
- Pass the place data to the action: PlaceForm.Record.Place;
- Use the returned values (PlaceId, Success, and ErrorMessage) to give feedback to the end-user;
- Publish and test.
One other situation for using this action is in the GoOut application, the mobile version of the GoOutWeb application. It happens when an end-user wants to write a review for a place that is not on the list. The place has to be created along with the review.
To implement this case learn also how to Expose and Reuse Code between Modules.