Skip to Content

Enable Multi-User Mode for MDK Application

Set up the Mobile Development Kit client to enable the multi-user mode (one device, multiple users with secure access).
You will learn
  • How to define an event on user switching
  • How to configure multi-user settings in mobile service admin UI
  • How to create an offline enabled MDK application that supports multiple users on the same device
jitendrakansalJitendra KansalFebruary 12, 2025
Created by
jitendrakansal
February 15, 2024
Contributors
jitendrakansal

Prerequisites

You may clone an existing metadata project from the MDK Tutorial GitHub repository and start directly with step 3 in this tutorial.

Multiple user mode is designed for enterprise scenarios where, for example, an employee uses a shared device during their shift. They may go offline while working in the field and return the device at the end of their shift. The next day, the employee might use a different device, while the device used previously could be assigned to another user. This is why it is called multiple user mode. In offline scenarios, multiple user mode ensures that the initial user’s data, stored offline, is synchronized with the server before the second user logs in. This process preserves the previous user’s changes to the data.

MDKMDK
  • Step 1

    This step includes creating a mobile project in SAP Build Lobby.

    1. In the SAP Build Lobby, click Create > Create to start the creation process.

      MDK
    2. Click the Build an Application tile.

      MDK
    3. Click the SAP Build Code tile to develop your project in SAP Business Application Studio, the SAP Build Code development environment, leveraging the capabilities of the services included in SAP Build Code.

      MDK
    4. Click the Mobile Application tile.

      MDK
    5. Enter the project name multiuserapp (used for this tutorial) , add a description (optional), and click Create.

      MDK

      SAP Build Code recommends the dev space it deems most suitable, and it will automatically create a new one for you if you don’t already have one. If you have other dev spaces of the Mobile Application type, you can select between them. If you want to create a different dev space, go to the Dev Space Manager. See Working in the Dev Space Manager.

    6. Your project is being created in the Project table of the lobby. The creation of the project may take a few moments. After the project has been created successfully, click the project to open it.

      MDK
    7. The project opens in SAP Business Application Studio, the SAP Build Code development environment.

      MDK

      When you open the SAP Business Application Studio for the first time, a consent window may appear asking for permission to track your usage. Please review and provide your consent accordingly before proceeding.

      MDK

  • Step 2

    The Storyboard provides a graphical view of the application’s runtime resources, external resources, UI of the application, and the connections between them. This allows for a quick understanding of the application’s structure and components.

    • Runtime Resources: In the Runtime Resources section, you can see the mobile services application and mobile destination used in the project, with a dotted-line connected to the External Resources.
    • External Resources: In the External Resources section, you can see the external services used in the project, with a dotted-line connection to the Runtime Resource or the UI app.
    • UI Application: In the UI Applications section, you can see the mobile applications.
    1. Click on + button in the Runtime Resources column to add a mobile services app to your project.

      MDK

      This screen will only show up when your CF login session has expired. Use either Credentials OR SSO Passcode option for authentication. After successful signed in to Cloud Foundry, select your Cloud Foundry Organization and Space where you have set up the initial configuration for your MDK app and click Apply.

      MDK
    2. Choose myapp.mdk.demo from the applications list in the Mobile Application Services editor.

      MDK
    3. Select com.sap.edm.sampleservice.v4 from the destinations list and click Add App to Project.

      MDK

      You can access the mobile services admin UI by clicking on the Mobile Services option on the right hand side.

      In the storyboard window, the app and mobile destination will be added under the Runtime Resources column. The mobile destination will also be added under the External Resources with a dotted-line connection to the Runtime Resource. The External Resource will be used to create the UI application.

      MDK
    4. Click the + button in the UI application column header to add mobile UI for your project.

      MDK
    5. In the Basic Information step, select the MDK Template Type as CRUD, leave the other options as they are, and click Next.

      MDK

      The Base template creates the offline or online actions, rules, messages and an empty page (Main.page). After using this template, you can focus on creating your pages, other actions, and rules needed for your application. More details on MDK template is available in help documentation.

    6. In the Data Collections step, provide the below information and click Finish. Data Collections step retrieves the entity sets information for the selected destination.

      | Field | Value |
      | Enter a path to service (e.g. /sap/opu/odata/sap/SERVICE_NAME) | Leave it as it is |
      | Select the Service Type | Leave the default value as OData |
      | Enable Offline | It’s enabled by default |
      | Select all data collections | Leave it as it is |
      | What types of data will your application contain? | Select Customers and Products |

      MDK

      Regardless of whether you are creating an online or offline application, this step is needed for app to connect to an OData service. When building an MDK Mobile application, it assumes the OData service created and the destination that points to this service is set up in Mobile Services. For MDK Web application, destination is set up in SAP BTP admin UI.

      Since you have Enable Offline set to Yes, the generated application will be offline enabled in the MDK Mobile client and will run as online in Web environment.

      Data Collections step retrieves the entity sets information for the selected destination.

    7. After clicking Finish, the storyboard is updated displaying the UI component. The MDK project is generated in the project explorer based on your selections.

      MDK
  • Step 3

    MDK provides an OnUserSwitch event that is called when the user is switched when the client is operating in Multi-User mode. This event is triggered after any pending Offline OData transactions from previous user are successfully synced.

    The purpose of the OnUserSwitch event is to inform the application that a user switch has taken place. Upon receiving this event, the application can execute any necessary actions to handle the user switch. At a minimum, this would involve running a Download action to update the offline store with the new user-specific data, while removing the data associated with the previous user.

    Since the underlying offline database is shared, it is the responsibility of the application developer to ensure that all necessary steps are taken to reinitialize the application for the new user to continue functioning properly.

    1. Click the Application.app to open it in MDK Application Editor and then and select the link icon for the OnUserSwitch event.

      MDK
    2. Bind it to the SyncStartedMessage.action.

      MDK

      For this tutorial, since we are using the Sample Service, which does not contain any user-specific data, we will simply trigger a sync to demonstrate that the event has been triggered.

  • Step 4

    Now that the MDK application is created, you will Deploy the Project definitions to Mobile Services to use in the Mobile client.

    1. Right-click Application.app and select MDK: Deploy.

      MDK
    2. Select deploy target as Mobile Services.

      MDK

      If you want to enable source for debugging the deployed bundle, then choose Yes.

      MDK

      You should see Deploy to Mobile Services successfully! message.

      MDK
  • Step 5
    1. Open SAP Mobile Services UI, click Mobile Applications Native/MDK click myapp.mdk.demo app.

      MDK
    2. Under Assigned Features, click Client Settings.

      MDK
    3. Scroll through the page and enable the Allow Upload of Pending Changes from Previous User (Enable Multiple User Mode) checkbox under the Shared Devices section. This flag ensures that any pending offline changes from previous user are securely uploaded to the OData service. This is especially vital when the previous user has not uploaded the offline changes, and the app is being switched to a new user.

      MDK
    4. As the Multiple user mode is enabled, you must configure Passcode Policy, if not done before.

      MDK
    5. Once the passcode policy is set, click Save.

    Is it mandatory to enable passcode policy in server side app configuration if multiple user mode is enabled?

  • Step 6

    In a Multi-user scenario the client will automatically upload any pending transactions from the previous user before completing the user switch. In order for Mobile Services to perform this upload it needs to get a token for the previous user. To do this XSUAA needs to trust Mobile Services. This is done by importing the Mobile Services key to the Trust Configuration in the BTP subaccount.

    1. In SAP Mobile Services admin UI, click Settings Security.

      MDK
    2. Click Metadata Download.

      MDK
    3. Define the metadata expiration date up to ten years, or you can accept the one-year default date. Click Download.

      MDK

      In case the metadata has been expired, end user may encounter an error while switching. You need to re-download the Mobile Services key and import it to the Trust Configuration in the BTP subaccount again.

    4. Save the SAMLMetadata.xml file locally on your machine.

    5. Navigate to your sub account on SAP BTP. In the Side navigation bar, click Security Trust Configuration and click New SAML Trust Configuration.

      MDK
    6. Click Upload, and select the XML file downloaded in the previous step, as a trusted identity provider. Enter a name, disable the Available for User Login checkbox and then click Save.

      MDK

      The trusted Identity Provider is not a real identity provider and cannot be used for user login. Disabling the Available for User Login checkbox ensures the identity provider does not appear on the XSUAA login page.
      For more information, see documentation.

  • Step 7

    Find out, if the metadata has been established successfully as a trusted provider.

    Switch to the SAP Mobile Services UI. Click Settings Security Test .

    MDK

    You should see a success message.

    MDK

    If the trust configuration is not established correctly, you may see a message like SAML metadata might not have been imported as trusted identity provider and the multi-user functionality in MDK client will not work.

  • Step 8

    If you are using SAP Mobile Services Client (public store) to test the multi-user functionality, you can skip this step.

    1. Follow steps 1 to 3 from Build Your Mobile Development Kit Client Using MDK SDK and make sure to set the MultiUserEnabled property to true.

      MDK
    2. Create your MDK client either using MDK SDK by following the step 4 from Build Your Mobile Development Kit Client Using MDK SDK tutorial OR using SAP Cloud Build Service by following Build Your Mobile Development Kit Client Using Cloud Build Service tutorial.

  • Step 9

    Choose an option above based on whether you are testing multi-user functionality in the SAP Mobile Services Client (public store) or in a branded client built using MDK SDK or Cloud Build service.

  • Step 10

    You have learned how to enable an Mobile Development Kit Client to support multi-user login capability. This means a Mobile Development Kit Client app on a device can now securely be shared across multiple users. Features such as adding a new user, switching between user sessions, searching for a particular user are supported by the client. Find more information about Multi User in MDK in help documentation.


Back to top