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 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

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 Creation step, provide and select the below information:

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

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 and SAP Cloud Platform.

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? Well, when you enabled Mobile Services, a destination mobileservices was created under Destinations in Cloud Platform Cockpit.
MDK

With help of mobileservices destination, SAP Web IDE fetches and populates all the MDK apps (of configuration template type as Mobile Development Kit) and their respective destinations.

You can look in 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.

Select Customers, products, SalesOrderHeaders and SalesOrderItems queries from the dropdown and click Finish.

MDK
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 learnt 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 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 is a list of NPM modules to be excluded from the bundle.

Based on the mobileservices destination, you will find list of existing MDK application IDs , select the one you have chosen while creating the project in step 1

MDK

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

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

MDK

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

MDK

Click the toast message to launch SAP Mobile Services Client.

On Android, camera app does not support scanning the QR code. You can use Lightning QR Scanner app to scan it.

MDK

Click Open link

MDK

It will open SAP Mobile Services Client app.

Before you click on Start in client app, first finish the deployment from SAP Web IDE. Click Next.

MDK

You should see Application deployed successfully message in console log.

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

Below steps & screenshots were captured with iOS device. You will have similar on-boarding experience with Android as well.

The MDK client receives deployed metadata definitions as a bundle.

Click Start to connect MDK client to SAP Cloud Platform.

MDK

Enter your SAP Cloud Platform credentials and click Log On to authenticate.

MDK

Agree on End User License Agreement.

MDK

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

MDK

Confirm the passcode and click Done.

MDK

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

MDK

Click OK.

MDK

Now, you will see Main page being displayed and Offline store is being initialized.

MDK
What is the Authentication option for mobileservices destination in SAP Cloud Platform Cockpit?
×

Next Steps

Prerequisites

Back to top