In OutSystems, you can make elements of your module available to be used by other modules. This allows you to reuse code, refactoring your application and create modular apps. With this practice, elements can be easily managed centrally in the module which provides them and, in the modules that use them as a reference, OutSystems can prompt you for changes and update them automatically at your command.
To make a module's element reusable:
- Select the element.
- In the properties pane, set the Public property to
Yes. This property will make your object public so other modules can use it.
- Publish the module.
To reuse an exposed element in a Consumer module:
- In the module where you want to reuse the element, open the Manage Dependencies window.
- Select the Producer module and then select the exposed element.
- Press OK to make it available in the module.
- Use the exposed element as any other element in the module.
Interface elements cannot be reused between web and mobile modules. Client actions and local storage entities can only be reused between mobile modules.
We have two applications, GoOutWeb, a web application, that allow users to check and review interesting places and its mobile counterpart, GoOut which reuses some of the web app's elements.
We want to allow users to add Reviews in either application. The Review entity is defined in the GoOutWeb app and we want to use it in the GoOut mobile app. To do this in a sustainable and efficient way, in GoOutWeb, we'll make the Review entity public and create an API with public actions to handle data related to the entity.
The public actions, implementing create (Review_Create) and set as inactive (Review_Inactive) operations for the Review entity. Review_Create receives a record of type Review, provides extra logic which validates input before persisting new records and Review_Inactive receives the Review Id of the review to set as inactive.
To make the Review entity and the Review_Create and Review_Inactive actions public:
- In the GoOutWeb application, open the Data tab.
- Select the Review entity.
- In the Properties editor of the entity, set the Public property to
Yes. This will expose the entity to be used by other modules along with its GetReview entity action. This will enable you to query the entity data but not manipulate it directly from a consumer module.
- In the Logic tab, for both Review_Create and Review_Inactive actions, edit their Public property and set it to
Yes. These actions will enable you to manipulate Reviews in another module.
- Publish the module.
To use the public GoOutWeb elements in the GoOut mobile app:
- Open the GoOut application.
- Click on Manage Dependencies... and select GoOutWeb from the producers list.
- Select the Review entity and Review_Create and Review_Inactive actions from the public elements available.
- Click OK.