Skip to Content

Create an MDK Online App

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

Create an MDK Online App

Use the mobile development kit editor to create a mobile app for online use case.

You will learn

  • How to create an MDK Online 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: Get familiar with use case

With mobile development kit, you can also create applications that are online or always connected and make calls to the backend servers for each action you take in the application.

Log on to answer question
Step 2: Set up the application foundation

Make sure that you have already created a new destination mobileservices_cf as per previous tutorial. This is required to connect SAP Web IDE to Mobile Services on Cloud Foundry environment.

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 MDKOnlineApp 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_cf
Application ID com.sap.mdk.demo
Service URL com.sap.edm.sampleservice.v2

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

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 this 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 Mobile Connectivity feature.
MDK

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

Leave the default configuration as it is and click Next and then click Finish.

MDK

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

Log on to answer question
Step 3: 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:

  • CreateService.action: This action binds the OData service to your application.

  • OpenService.action: This action allows your application to see the data within the OData service.

  • CreateOpenService Success & Failure Message action: Here are some messages showing up in the app on a successful or failure of application data service initialization.

  • 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

In MDK online use case, you need create and open service actions chained together for your online provider.

CreateService.action should be set at OnLaunch and success of this action should call OpenService.action.
MDK

You can find more details about OData actions.

Log on to answer question
Step 4: 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 MDKOnlineApp 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 5: 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 MDKOnlineApp 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

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

MDK
Log on to answer question
Step 6: 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 Main page being displayed and application data service is 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 Main page being displayed and application data service is initialized.

MDK

You can now continue creating your first page to show customers list.

Which action is being called at OnLaunch event in application.app file?
×

Next Steps

Prerequisites

Back to top