Skip to Content

Modify a Customer Record in an MDK App

Allow editing of customer details in an MDK app.
You will learn
  • How to create a new page for modifying customer details such as name, email and phone number
  • How to store changes locally on Mobile app and sync these changes with backend
  • How to update a record in web application
jitendrakansalJitendra KansalJuly 8, 2022
Created by
jitendrakansal
April 23, 2019
Contributors
jitendrakansal
jitendrakansal
jitendrakansal
MDK
  • Step 1

    Regardless of whether your application is online or offline, you can allow users to modify data in the application.

    For online applications, the changes are saved to the backend immediately.

    For offline applications, the changes are stored locally until they are synced using an Upload action.

    In this step, you will create the Edit Customer Detail page as a Form Cell Page. This type of page allows for form input style changes. The page will provide only a subset of items available on the Customer Detail page. You will add the fields that will be editable by the end-user.

    1. Right-click the Pages folder | MDK: New Page | Form Cell Page | Next.

      MDK

      A Form Cell Page is suitable for pages that generate new objects or modify existing objects. It includes a form cell container by default. You can add multiple containers or action controls to this page. Under each container section, you can add various controls.

      You can find more details about Form Cell page.

    2. Enter the Page Name Customers_Edit and click Next and the Finish on the Confirmation step.

      MDK
    3. In the Properties pane set the Caption to Update Customer.

      MDK
    4. Now, you will add the fields (like first name, last name, phone & email address) that will be editable by the end-user.

      In the Layout Editor, expand the Controls group.

      Drag and drop a Simple Property onto the Page area.

      MDK
    5. Drag and drop three additional Simple Property controls onto the page so you have four total controls.

      MDK
    6. Select the first Simple Property control and provide the below information:

      Property Value
      NameFCFirstName
      Caption First Name
      Valueclick the link icon and bind it to FirstName property of the Customer entity
      MDK
    7. Select the second Simple Property control and provide the below information:

      Property Value
      NameFCLastName
      Caption Last Name
      Valueclick the link icon and bind it to LastName property of the Customer entity
      MDK
    8. Select the third Simple Property control and provide the below information:

      Property Value
      NameFCPhone
      Caption Phone
      Valueclick the link icon and bind it to PhoneNumber property of the Customer entity
      MDK
    9. Select the last Simple Property control and provide the below information:

      Property Value
      NameFCEmail
      Caption Email
      Valueclick the link icon and bind it to EmailAddress property of the Customer entity
      MDK

    In which file format is the Mobile Development Kit (MDK) metadata defined?

  • Step 2

    You will create a CloseModalPage_Cancel.action that closes the current page and cancels or interrupts any execution in process. This will be used with the cancel button on the Edit Customer page.

    You can close pages with the option to terminate ongoing events or wait until they are complete. Visit documentationfor more details about Close Page Action.

    1. Right-click the Actions folder | MDK: New Action | choose MDK UI Actions in Category | click Close Page Action | Next.

      MDK
    2. Provide the below information:

      Property Value
      Action NameCloseModalPage_Cancel
      DismissModal Select Canceled from the dropdown
      CancelPendingActionsSelect true from the dropdown
      MDK
    3. Click Next and then Finish on the confirmation step.

  • Step 3

    Now, you will add a button on the Edit Customer page and set it’s onPress to CloseModalPage_Cancel.action created in step 2.

    1. In Customers_Edit.page, drag and drop an Action Bar Item control to the upper left corner of the action bar.

      Action Bar Item is a button that users can use to fire actions when pressed. You can add an Action Bar Item only to the Action Bar (at the top of the page).

      MDK
    2. In the Properties pane, click the link icon to open the object browser for the System Item property.

      Double-click the Cancel type and click OK.

      MDK

      System Item are predefined system-supplied icon or text. Overwrites Text and Icon if specified.

    3. Now, you will set the onPress event to CloseModalPage_Cancel.action.

      In Events tab, click the 3 dots icon for the OnPress property to click the Object Browser.

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

      MDK
  • Step 4

    Now, create a navigation action that will open the Customers_Edit.page when executed.

    1. Right-click the Actions folder | MDK: New Action | choose MDK UI Actions in Category | click Navigation Action | Next.

      MDK
    2. Provide the below information:

      Property Value
      Action NameNavToCustomers_Edit
      PageToOpen Select Customers_Edit.page from the dropdown
      ModalPageSelect true from the dropdown
      MDK
    3. Click Next and then Finish on the confirmation step.

  • Step 5

    You will add a button to the Customers_Detail.page called Edit. You will link this button to the navigation action you just created. This event will open the Customers_Edit.page when the Edit button is pressed by the end-user.

    1. In Customers_Detail.page, drag and drop an Action Bar Item to the upper right of the action bar.

      MDK
    2. Click the link icon to open the object browser for the System Item property.

      Double-click the Edit type and click OK.

      MDK
    3. In the Properties pane, click the Events tab, click the 3 dots icon for the OnPress property to open the Object Browser.

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

      MDK
  • Step 6

    The next step is to store newly updated record locally for an offline application or send the updated record directly back to the backed for online applications. You will now create an action to map the changes received from the Customers_Edit.page to the corresponding field in the OData service. You will also show a failure message if the update action fails to save the changes.

    First, define a failure message.

    1. Right-click the Actions folder | MDK: New Action | choose MDK Message Actions in Category | click Message Action | Next.

      MDK
    2. Provide the below information:

      Property Value
      Action NameUpdateCustomerEntityFailureMessage
      Type Select Message from the dropdown
      Message Failed to Save Customer Updates
      Title Update Customer
      OKCaption OK
      OnOK --None--
      CancelCaption leave it blank
      OnCancel --None--
      MDK
    3. Click Next and then Finish on the confirmation step.

    4. Next, you will define Close Page-Complete Action which allows the end-user to close the page and allow any execution to continue.

      You can close pages with the option to terminate ongoing events or wait until they are complete.

      Right-click the Actions folder | MDK: New Action | choose MDK UI Actions in Category | click Close Page Action | Next.

      MDK
    5. Provide the below information:

      Property Value
      Action Name CloseModalPage_Complete
      DismissModal Select Completed from the dropdown
      CancelPendingActions Select false from the dropdown
      MDK
    6. Click Next and then Finish on the confirmation step.

    7. Next, you will create the OData Update action to update entity action that will map the changes to the correct entities in the OData service and save the changes.

      You can find more details about Update Entity Action.

      Right-click the Actions folder | MDK: New Action | choose MDK Data Actions in Category | click OData Action | Next.

      MDK
    8. In the Operation and Service Selection step, provide the below information:

      Property Value
      Action NameCustomers_UpdateEntity
      Type Select UpdateEntity from the dropdown
      ServiceSelect SampleServiceV2.service from the dropdown
      EntitySetSelect Customers from the dropdown
      ReadLinkclick link icon and Double-click readLink
      MDK

      The readLink is a direct reference to an individual entity set entry.

    9. Click Next.

    10. In Property and Update Links step, uncheck City.

    11. Since in Customers_Detail.page, you defined four properties (First Name, Last Name, Phone & Email) to be edited, now, in this step, you will bind them to respective UI Controls.

      Check the EmailAddress property and click the link icon to open the object browser.

      Change the drop down in the object browser to Controls & ClientData, click the Current Page radio button.

      In the search box start typing the control name FCEmail. The list will filter down to show the matching values. Double-click the Value (Value) entry under the FCEmail field and click OK to set binding.

      MDK
    12. Repeat the above step for remaining properties: FirstName, LastName and PhoneNumber.

      MDK

      Click Next and Finish on the confirmation screen. The action editor will open with the Customers_UpdateEntity.action loaded.

    13. Next, define Success and Failure actions for Customers_UpdateEntity.action.

      In the action editor for the new action, expand the Common Action Properties and provide the below information:

      Property Value
      Success Action Click the link icon and bind it to CloseModalPage_Complete.action
      Failure Action Click the link icon and bind it to UpdateCustomerEntityFailureMessage.action

      When Customers_UpdateEntity.action gets executed successfully then CloseModalPage_Complete.action will be triggered or if Customers_UpdateEntity.action fails then UpdateCustomerEntityFailureMessage.action will be triggered.

      MDK
    14. Next, you will set the OnPress event of the Save button.

      Now, that the Update action is created, you will need to call the Update action when the end-user presses the Save button. You will add a Save button on the Customers_Edit.page and link it to the Customers_UpdateEntity.action.

      In Customers_Edit.page, drag and drop an Action Bar Item to the upper right corner of the action bar.

      MDK

      Click the link icon to open the object browser for the System Item property.

      Double-click the Save type and click OK.

      MDK
    15. In the Properties pane | Events tab, click the 3 dots icon for the OnPress property to open the Object Browser, bind it to Customers_UpdateEntity.action.

      MDK

    What is the ReadLink value set in Customers_UpdateEntity.action?

  • Step 7

    Deploy the updated application to your MDK client.

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

      MDK
    2. Select deploy target as Mobile & Cloud.

      MDK

      You should see success message for both deployments.

      MDK

      Alternatively, you can select MDK: Redeploy in the command palette (View menu>Find Command OR press Command+Shift+p on Mac OR press Ctrl+Shift+P on Windows machine), it will perform the last deployment.

      MDK

    What features does SAP Business Application Studio offer for developing MDK apps?

  • Step 8

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

Back to top