Skip to Content

Create an MDK Offline App

test
0 %
Create an MDK Offline App
Details
// Explore More Tutorials

Create an MDK Offline App

Use the mobile development kit editor to create a mobile app.

You will learn

  • How to create an MDK app using an existing template in SAP Web IDE
  • How to deploy an MDK app to Mobile Services and run it in a client


Step 1: Set up the application foundation

This step includes creating the Mobile Development Kit project in the Editor.

Launch the SAP Web IDE and select the MDK perspective by clicking on the icon in the left panel.

Right click on Workspace folder and select New | MDK Base Project.

MDK

The MDK Base Project 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.

Enter the Project Name as DemoSampleApp and click Next.

MDK

Leave the default values in Application Creation step as it is, click Next.

In Service Configuration step, provide and select the below information:

Field Value
Name SampleServiceV2
Service URL select /destinations/mobileservices_cf destination
Application ID com.sap.mdk.demo
Destination Name com.sap.edm.sampleservice.v2
Enable Offline Store Should be checked

If you do not find mobileservices_cf destination, please ensure that you have followed this tutorial to setup this destination in SAP Cloud Platform cockpit.

For Offline OData capability only OData V2 is supported. OData V2 and V4 are supported for Online OData.

MDK

In previous tutorial, server-side configuration for this MDK app were already done.

Regardless of whether you are creating an online or offline application, this step is needed app to connect to an OData service. When building an Mobile Development Kit application, it assumes the OData service created and the destination that points to this service is setup in Mobile Services.

Since you will create an offline based app, hence Enable Offline Store option is selected.

Click Check Service to validate the service properties. If all the details are fine, you will see a success message. Click Next.

MDK

Wondering how Service URL, Application ID & Destination Name were populated? As part of enabled Mobile Services tutorial, you created a destination mobileservices_cf in Cloud Platform Cockpit, SAP Web IDE fetches all these details based on this destination.
MDK

You can look in SAP Cloud Platform Mobile Services Cockpit for the destination belongs to the MDK app by clicking on Connectivity feature.
MDK

More details on Sample Back End is available in help documentation.

In the Features step, click the Queries drop down and select Customers, Products, SalesOrderHeaders and SalesOrderItems and click Finish.

MDK

After clicking Finish, the wizard will generate your MDK Application based on your selections. You should now see the DemoSampleApp project in the project explorer.

Log on to answer question
Step 2: Get familar with generated project structure

This is how the project structure looks like within the workspace.

MDK

These are the metadata definitions available in the editor and the format in which these metadata definitions are stored in the editor. Just to brief on some of these -

InitializeOffline.action: For offline applications, this action binds the application to the Offline OData server and downloads the required data to the offline store on the mobile device.

DownloadOffline.action and UploadOffline.action: Using app initialization, data is downloaded to the offline store. If you want to have the application download any updated data from the backend server or upload changed data to the backend server, these actions will be needed.

Success & Failure Message action: Here are some messages showing up in the app on a successful or failure of data initialization, sync etc.

Main.page: This is the first page of your Mobile Development Kit application that is shown. For this application we will use this as a launching page to get to application functionality. We will add the logout action to this page.

OnWillUpdate.js: MDK applications automatically download updates and apply them to the client without the end-user needing to take any action. The OnWillUpdate rule empowers the user to run business logic before the new definitions are applied. This allows the application designer to include logic to prompt the user to accept or defer applying the new definitions based on their current activity. For example, if the end-user is currently adding new customer details or in the middle of a transaction, they will be able to defer the update. The application will prompt again the next time it checks for updates.

Application.app: this is the main configuration file for your application from within SAP Web IDE. Here you set your start page (here in this tutorial, it is main.page), action settings for different stages of the application session lifecycle, push notifications, and more.

You can find more details about metadata definitions.

Open the application settings in the application editor by double clicking on the Application.app in the project explorer pane.

MDK
Log on to answer question
Step 3: Deploy and activate the application

So far, you have learned how to build an MDK application in the SAP Web IDE editor. Now, we deploy this application definition to Mobile Services.

Right click on the DemoSampleApp MDK Application in the project explorer pane and select MDK Deploy and Activate.

MDK

Let the default configuration as it is and click Next.

MDK

Filter Files will be filtered and ignored in web packing process.

Externals are the list of NPM modules that are part of the MDK Client application and should not be validated in the bundle.

Click the drop down for Destination Name and select the mobileservices_cf destination, you will find list of existing application IDs, select the one you have chosen while creating the project.

MDK

By default, automatically deploy option is selected, In other words, the application is automatically deployed from Mobile Services to your MDK client.

Click Next to finish the deployment from SAP Web IDE.

You should see Application deployed successfully message in console log.

MDK
Log on to answer question
Step 4: Populate the QR code for app on-boarding

SAP Web IDE has a feature to generate QR code for app on-boarding.

Right click on the DemoSampleApp MDK Application in the project explorer pane and select MDK Deploy and Activate.

MDK

Click Next.

MDK

Click on the QR-code icon to populate the QR-code for app on-boarding.

MDK
Log on to answer question
Step 5: Run the app in MDK client

Make sure you are choosing the right device platform tab above.

On Android, the camera app does not support scanning the QR-code. As alternative you can use the Barcode scanner app to scan it.

Open the Barcode scanner app and start scanning the QR code showing in SAP Web IDE.

Tap Open browser. It will open SAP Mobile Services Client app.

MDK

Tap GET STARTED to connect MDK client to SAP Cloud Platform.

MDK

Enter Email address and password to login to SAP Cloud Platform and tap Log On to authenticate.

MDK

Tap AGREE on End User License Agreement.

MDK

Choose a passcode with at least 8 characters for unlocking the app and tap NEXT.

MDK

Confirm the passcode and tap DONE.

MDK

Optionally, you can enable fingerprint to get faster access to the app data.

MDK

Tap OK.

MDK

The MDK client receives deployed metadata definitions as a bundle.

Now, you will see the Main page (with Logout and Sync options at bottom of the page) being displayed and Offline store is being initialized.

MDK

On iPhone, open your camera app and start scanning the QR code, as shown below.

MDK

Tap the toast message to launch SAP Mobile Services Client. It will open SAP Mobile Services Client app.

Tap Start to connect MDK client to SAP Cloud Platform.

MDK

Enter Email address and password to login to SAP Cloud Platform and tap Log On to authenticate.

MDK

Tap Agree on End User License Agreement.

MDK

Choose a passcode with at least 8 characters for unlocking the app and tap Next.

MDK

Confirm the passcode and tap Done.

MDK

Optionally, you can enable Touch ID to get faster access to the app data, tap Enable.

MDK

Tap OK.

MDK

The MDK client receives deployed metadata definitions as a bundle.

Now, you will see the Main page (with Logout and Sync options at bottom of the page) being displayed and Offline store is being initialized.

MDK
Which is main configuration file in an MDK project?
×

Next Steps

Prerequisites

Back to top