Skip to Content

Use OData Annotations to Add CRUD Functionality to an MDK App

test
0 %
Use OData Annotations to Add CRUD Functionality to an MDK App
Details

Use OData Annotations to Add CRUD Functionality to an MDK App

September 10, 2020
Created by
September 27, 2019
Create a fully functional CRUD native mobile application for iOS and Android.

You will learn

  • How to retrieve OData annotations for Products in Mobile Services sample OData service
  • How to create a fully functional Mobile app

Prerequisites

You may clone an existing project from GitHub repository and start directly with step 5 in this tutorial but make sure you complete step 2.


Mobile Development Kit brings OData annotations capabilities to your native mobile applications. MDK editor supports generating List-Detail pages based on annotations. List-Detail pages are similar to a Master-Detail page, but it is two pages instead of one. The MDK editor parses existing annotations to give you a huge leap forward in your native mobile application.

MDK
Step 1: Understand the SAP Fiori Elements

If you are a Fiori app designer, you may already be familiar with OData annotations and smart templates.

SAP Fiori elements provide designs for UI patterns and predefined templates for common application use cases. App developers can use SAP Fiori elements to create SAP Fiori applications based on OData services and annotations. With little or no coding, you can create SAP Fiori applications. UI5 has a Web solution, named smart templates, that builds a starter application by parsing the annotations in your OData service.

You can also check out more information on the Fiori elements List Report and Smart templates

Log on to answer question
Step 2: Add annotation information in the backend destination

Sample backend in SAP Cloud Platform Mobile Services provides annotation functionality for Products. If you add annotation path in given backend endpoint, the same annotation information can be Leveraged by MDK editor to generate related CRUD pages.

Make sure you have already configured an app in Mobile Services cockpit and have added Sample service as per this tutorial.

As admin changes to the default sample service destinations (com.sap.edm.sampleservice.v2 and com.sap.edm.sampleservice.v4) are not allowed, you need to copy the destination URL from the sample service destination com.sap.edm.sampleservice.v2 and create a new destination with the new name e.g., com.sap.mdk.annotation and add the required annotations.

  1. In SAP MDK Demo App configuration, click Mobile Connectivity.

    MDK
  2. Copy the destination URL from the sample service destination com.sap.edm.sampleservice.v2.

    MDK
  3. Click create icon to create a new destination.

    MDK
  4. Enter a new destination name com.sap.mdk.annotation and paste the URL. Click Next.

    MDK
  5. For this tutorial, there is no Custom Headers required, click Next.

    MDK
  6. Click Add Annotation URL to add OData Annotations to the Sample service.

    MDK

    Provide the below information and click Next:

    Field Value
    Annotation Name Product
    Path/File /annotations/Products
    MDK
  7. In Create Destination screen, select SSO Mechanism as Forward Authentication and click Next.

    MDK
  8. In the following screen, let the default settings as it is. Click Finish.

    MDK

    You should see a Toast Message Destination Created at bottom of the page.

    Here you can see that OData Annotation information is available in the new destination.

    MDK
Log on to answer question
Step 3: Create a new MDK project in SAP Business Application Studio

This step includes creating the mobile development kit project in the editor.

  1. Launch the Dev space in SAP Business Application Studio.

  2. If you do not see the Welcome page, navigate to View menu → Find Command → search with Welcome to launch the Welcome page.

    MDK
  3. In Welcome page, click New project from template .

    MDK
  4. Select MDK Project and click Next.

    MDK
  5. In Basic Information step, select or provide the below information and click Next:

    Field Value
    MDK Template Type Select Base from the dropdown
    Your Project Name MDK_Annotations
    Your Project Name <default name is same as Project name, you can provide any name of your choice>
    MDK

    More details on MDK template is available in help documentation.

  6. In SAP Cloud Platform Connection step, you will see your Cloud Foundry Organization and Space information. If you are not logged on yet, provide required credentials to retrieve your details. Click Next.

    MDK
  7. In Service Configuration step, provide or select the below information and click Next:

    Field Value
    Service File Name <You can continue with default name or provide any name of your choice>
    OData Source Select Mobile Services from the dropdown
    Application Id Select com.sap.mdk.demo from the dropdown
    Destination Select com.sap.mdk.annotation from the dropdown
    Enable Offline Choose No
    MDK

    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 online based app, hence Enable Offline Store option is unchecked.

  8. After clicking Next, the wizard will generate your MDK Application based on your selections. You should now see the MDK_Annotations project in the project explorer. As you have already opened the workspace, there is no need to open the generated project in new workspace or to add it to workspace. Ignore the pop-up or click the cross icon to hide the window.

    MDK
Log on to answer question
Step 4: Add MDK Annotation component to MDK project
  1. Right-click Application.app and select MDK:New MDK Annotation Component.

    MDK
  2. MDK editor fetches annotation details, select Product Annotation and click Next.

    MDK
  3. In Template Customization step, click Next.

    MDK
  4. Click Finish to create list detail from OData Annotation.

    MDK

    In MDK project, you will see new pages, actions, rules have been generated for Product.

    MDK
  5. Next, you will add a Toolbar item on Main.page to navigate to Product_List.page.

    In Main.page, drag and drop Toolbar Item control on the page.

    MDK
  6. Change its Caption to Products.

    MDK
  7. Now, you will set the onPress event to NavToProduct_List.action.

    In Events tab, click the link icon for the OnPress property to open the object browser.

    Double-click the NavToProduct_List.action and click OK to set it as the OnPress action.

    MDK

    Pages, actions and rules created are a starting point. You can edit those pages and make it your own. At this point the MDK editor is no longer reading the annotations from OData.

    For the List page, MDK supports the List Report. To create a Detail page, MDK requires UI.LineItem and UI.HeaderInfo in the annotation file.

    If the OData designer updates the backend services data schema (annotations), the MDK pages will stay as originally created. It will not automatically update the pages or overwrite your changes. You are disconnected from the annotations at this point.

Which page is not part of generated pages in Product folder?
×
Step 5: Deploy and activate the application

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

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

MDK

You should see Deploy Succeeded message.

MDK
Log on to answer question
Step 6: Populate the QR code for app onboarding

SAP Business Application Studio has a feature to generate QR code for app onboarding.

Double-click the Application.app to open it in MDK Application Editor and click Application QR Code icon to populate the QR code.

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

Make sure you are choosing the right device platform tab above. Once you have scanned and onboarded using the onboarding URL, it will be remembered. When you Log out and onboard again, you will be asked either to continue to use current application or to scan new QR code.

  1. Follow these steps to on-board the MDK client.

    Once you accept app update, you will see the Main page with LOGOUT and PRODUCTS options at bottom of the page. Tap PRODUCTS, you will navigate to Product List page.

    MDK
  2. In following pages, you can create a new record, modify an existing record and even delete the record.

    MDKMDK
  1. Follow these steps to on-board the MDK client.

    Once you accept app update, you will see the Main page with Logout and Products options at bottom of the page. Tap Products, you will navigate to Product List page.

    MDK
  2. In following pages, you can create a new record, modify an existing record and even delete the record.

    MDKMDK

Congratulations! You have successfully created a fully functional CRUD native mobile application based on OData annotations and you are now all set to Enable Push Notifications in the MDK Public Store Client.

Log on to answer question

Next Steps

Back to top