Share Data Between Apps

Last update: Edit

1 Introduction

This how-to will demonstrate how easy it is to build apps using data from different sources using Mendix Data Hub. The steps will describe the following:

  • Create a simple app in Studio Pro
  • Publish an entity from the app and register it in the Data Hub Catalog
  • Use the Data Hub Catalog to explore the entities that are available in the organization
  • Connect to the registered entity in a new app
  • Change data in the original app and see it updated in the consuming app
  • See the network of shared data in the Data Hub Landscape

2 Prerequisites

Before starting this how-to, make sure you have completed the following prerequisite:

3 Creating an App

Follow these steps to create a simple app in Studio Pro whose data you will use in another app:

  1. In Studio Pro, click New App to create a new app project using the Blank App template. Call this app {yourname}CustomerServiceApp.
  2. Open MyFirstModule > Domain Model and click Entity in the toolbar above the main window to add an entity to your domain model.
  3. Double-click the entity to open its properties and change its Name to Customer.
  4. In the Attributes tab, click New to create the following attributes for the entity:

    Name Type
    CustomerId Autonumber
    FirstName String
    LastName String
    CompanyName String
    Address String

  5. Click OK to see the entity and attributes in the domain model.

  6. Right-click the entity and from the menu, select Generate overview pages.

  7. In the Generate pages dialog box, select Atlas_Default(Atlas_UI_Resources) as the Content layout and click OK. Overview pages for the new entity will be added in the OverviewPages folder of MyFirstModule.

  8. In the Project Explorer, double-click Home_Web to open the Home_Web page.

  9. From the Project Explorer drag Customer_Overview into the Auto-fill container under the “Welcome” banner.

    You have now created a simple app with the entity Customer and a web page where you can add data and view and edit details for this entity. Go ahead and customize your Home page further by changing the banner text.

4 Publishing to the Data Hub Catalog

You are going to register the Customer entity in the Data Hub Catalog. This means you will be providing access to the data that will be associated with this entity for use in other apps. To do this you have to expose the Customer entity in a published OData service in Studio Pro. OData V3 is a REST-based protocol and a standard format that is used for registering services and the entities that are exposed in the service in the Data Hub Catalog.

When the app is deployed to the Mendix Cloud v4, the service is automatically registered in the Data Hub Catalog along with the exposed entity.

The following steps take you through creating an OData service for your app to expose the Customer entity and register it in the Data Hub Catalog.

  1. Add a folder called APIs to MyFirstModule.

  2. In the domain model, right-click the Customer entity and select Expose as OData resource….

  3. In the Select Published OData Service dialog box, select the MyFirstModule > APIs folder and click New to add a new OData service. Call this published OData service {yourname}CustomerODataService and press OK.

    The new {yourname}CustomerODataService is added to the module and the Edit published resource dialog box is displayed for the entity Customer.

  4. Click Select… to take a look at the list of Exposed attributes and associations. You will see the list of attributes that you defined in the last section. When publishing an entity to an OData service you can select the attributes that you want to expose in the service from here.

  5. Click OK twice to display the OData Service document. You will see the details of the service that will be included in the service metadata files and be registered in the Data Hub Catalog.

    Under Resources, the Customer entity is listed.

  6. Click Run to deploy the app. When prompted, click Save and continue to save any unsaved changes to the app. The app will be deployed, and the OData service will be automatically registered in the Data Hub Catalog.

  7. Once the app is deployed, click View to open the app in your browser. Your app is now ready to use.

  8. On the app’s home page, click Customers Overview.

  9. Click New to add data for a customer entry.

  10. You can now add data to this entity. Go ahead and add several customers.

    external entities

    When this entity is consumed in another app via the Data Hub Catalog, a connection will be made to the data that that you enter here.

5 Using the Data Hub Catalog and Curating your own Service

The {yourname}CustomerODataService from your app is now registered in the Data Hub Catalog and can be used in other apps. To explore the Data Hub Catalog and find this service and the exposed Customer entity, follow these steps:

  1. Go to Mendix Data Hub:

    Data Hub screen

  2. In the search field, enter the search term customer. All services and entities that satisfy this search string will be displayed in the Search Results pane in the Search Details screen.

  3. From the search results, find the service that you published and select it. Full details will be displayed in the Search Details screen and the service metadata pane on the right. This information was defined in the OData service document in Studio Pro.

    If you have curate permissions (meaning, you are the owner of a service, a curator, or a Data Hub Admin), you will also see the curation bar and you will see that it will show that “You are the owner of the service“:

    data hub

​ The curation bar, highlighted in the image above, enables you to edit details of the registered service and also set the Discoverability to other users. By default, services registered through a Studio Pro deployment will be set to Discoverable. For further details about curating services, see How to Curate Registered Assets.

For more details on searching in the Data Hub Catalog and the Search Details screen, see How to Search in the Data Hub Catalog. You can also explore registered services in the Data Hub Landscape. For more information, see How to Use the Data Hub Landscape.

6 Using the Customer Entity in Another App

You are now going to create a new app and consume the data you have added to the Customer entity through the {yourname}CustomerODataService service.

Perform the following steps:

  1. In Studio Pro, create a new app using the Blank App template and call it {yourname}CustomerActionsApp.

  2. Go to the domain model.

    The Data Hub pane will be displayed on the right.

    data hub pane

    If you do not see the Data Hub pane, click View > Data Hub to display the Data Hub pane:

  3. In the Data Hub pane, enter the search string customer.

    The search results will be listed in the Data Hub pane showing all the services and entities satisfying this search string. You will note that the app that you have created is not listed.

    By default, search in the Data Hub pane will only show services in production environments. The app that you have deployed in this how-to was deployed to the Mendix Cloud for Free Apps.

  4. Click the Filter icon next to the search area to include this non-production environment in your search:

    Filter Icon
  5. Check Show development environments. The search results will now show results for all environments including the {yourname}CustomerOData_service which is available in the Mendix Free App environment (which is displayed as Sandbox in the example below):

    data hub pane
  6. Find {yourname}CustomerODataService and drag the Customer entity from this service into the domain model for your app. The consumed service and entity will be shown in the Data Hub pane with a green check mark against them.

  7. Click the information icon for the consumed service in the Data Hub Pane to see further information about the service as it is registered in the Data Hub Catalog. You can also click View in Data Hub Catalog to go to the service details screen in the Data Hub Catalog.

    external entities

    In the Project Explorer, the service and location documents for the external entity that you have just included in your domain model are now listed. These documents contain the metadata for the service and provide the links for connecting to the shared data.

    external entities

  8. Right-click the entity and select Generate overview pages to generate overview pages for this entity.

  9. In the Generate pages dialog box, for Content layout select Atlas_Default(Atlas_UI_Resources) and click OK. Overview pages for the new entity will be added to the MyFirstModule module.

  10. Open the Home_Web page and, from Project Explorer, drag Customers_Overview into the Auto-fill container under the “Welcome” banner. Go ahead and add a new banner and welcome text.

  11. Click Run to deploy the app. The app will be deployed and a link established to the data associated with the Customer entity in the publishing app ({yourname)CustomerServiceApp) through the {yourname)CustomerODataservice.

7 Viewing the Shared Data in Your New App

To view the consumed data in your new app, follow these steps:

  1. When the app has successfully been deployed, click View to open the app in the browser.
  2. Click Customer Overview.

    The overview page displays the list of the customers that you entered in the {yourname}CustomerServiceApp app.

8 Seeing Changes in Data in the Consuming App

To see an example of consumed data being updated when data is changed in the originating app, follow these steps:

  1. Open both apps that have been created in this how-to in separate browser windows and display them side by side.
  2. Make some changes to the customer list in {yourname}CustomerServiceApp by adding a few more customers to the list and editing some existing entries.
  3. Refresh the {yourname}CustomerActionsApp window by doing a Search to see the changes in the data displayed.

In the example below, the consuming app is on the right:

Congratulations, you have successfully used the Data Hub Catalog functionality to share data between Mendix apps!

You can now see your new apps in your organization’s Data Hub Landscape.

9 Viewing Your Apps in the Data Hub Landscape

You will now learn how to do the following:

  • Use and understand the Data Hub Landscape for locating sources of data
  • View the dependencies between deployed apps and the direction of the dependencies in your Data Hub Landscape

You can view the two apps that you have created in the Data Hub Landscape and see the associations by following these steps:

  1. Open the Data Hub home page.
  2. Click the Landscape tab to see a graphical representation of your company’s data landscape
  3. Find your app using the search pane. Remember to use the filter to ensure you can see sandbox apps:

    In the Data Hub Landscape registered services are shown as circles with the number of entities that have been exposed in the service.

    The service {yourname}CustomerODataAPI is linked by a solid line to the runtime instance of {yourname}CustomerCustomerServiceApp (shown as a square icon), which is deployed as a Free App.

    The service is also linked by a dotted grey line to {yourname}CustomerActionsApp with an arrow that indicates that it is making a call to the service for data (or consuming data from it). If you click the entity icon on this consume line, the entities that are being consumed will be listed in the metadata panel.

  4. Click a node to see details of the selected item in the Data Hub Catalog metadata panel on the right. You can also click the Search tab to see full details in the Search Details screen.

  5. Go ahead and search for another item. For large networks, you can use your mouse to zoom in out and pan around the landscape.