Skip to main content

Developing an Application

 

OutSystems

Expose and Reuse Code Between Modules

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:

  1. Select the element;
  2. In the properties pane, set the Public property to Yes. This property will make your object public so other modules can use it;
  3. Publish the module;

To reuse an exposed element in a Consumer module:

  1. In the module where you want to reuse the element, open the Manage Dependencies window;
  2. Select the Producer module and then select the exposed element;
  3. Press OK to make it available in the module;
  4. 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.

Example

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:

  1. In the GoOutWeb application, open the Data tab;
  2. Select the Review entity;
  3. 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;
  4. 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.
  5. Publish the module.


Reusing code between modules, setting property Public to yes

To use the public GoOutWeb elements in the GoOut mobile app:

  1. Open the GoOut application;
  2. Click on manage_module_dependencies.png Manage Dependencies... and select GoOutWeb from the producers list;
  3. Select the Review entity and Review_Create and Review_Inactive actions  from the public elements available.
  4. Click OK.

Reusing code between modules, adding code as a dependency

  • Was this article helpful?