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 KansalJanuary 30, 2023
Created by
jitendrakansal
October 4, 2022
Contributors
maximilianone
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 | 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. In the Base Information step, enter the Page Name Customers_Edit and click Finish to complete the page creation process.

      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
      KeyboardType Phone
      Valueclick the link icon and bind it to PhoneNumber property of the Customer entity
      MDK

      To streamline data entry, the keyboard displayed when editing a SimplePropertyFormCell should be appropriate for the type of content in the field. If your app asks for number, for example, it should display the phone keyboard.

    9. Select the last Simple Property control and provide the below information:

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

      To streamline data entry, the keyboard displayed when editing a SimplePropertyFormCell should be appropriate for the type of content in the field. If your app asks for an email address, for example, it should display the email address keyboard.

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

  • Step 2

    While updating the customer details, you may want to close the current page and cancels or interrupts any execution in process.

    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. Navigate to the Events tab. Click the 3 dots icon for the OnPress property and select the Create a rule/action.

      MDK
    4. Keep the default selection for the Object Type as Action and Folders path.

      MDK
    5. Choose UI in Category | click Close Page | Next.

      MDK
    6. In the Base Information, provide the below information and then click Finish to complete the action creation process.

      Property Value
      NameCloseModalPage_Cancel
      DismissModal Select Canceled from the dropdown
      CancelPendingActionsSelect true from the dropdown
      MDK

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

  • Step 3

    The next step is to store the updated record locally for an offline application or send the updated record directly back to the backed for online applications.

    • You will now add an Action Bar item on the Customers_Edit.page that will call an OData Update Entity action to save the record
    • You may want to close the page when the update action is successful
    • You may want to show a failure message if the update action fails to save the changes

    First, add an action bar item on the Customers_Edit.page

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

      MDK
    2. Click the link icon to open the object browser for the System Item property. Double-click the Save type and click OK.

      MDK
    3. Navigate to the Events tab. Click the 3 dots icon for the OnPress property and select the Create a rule/action.

      MDK
    4. Keep the default selection for the Object Type as Action and Folders path.

      MDK
    5. Choose Data in Category | click OData | Next.

      MDK
    6. In the Base Information step, provide the below information:

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

      This action will map the changes to the correct entities in the OData service and save the changes.

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

    7. Click Next.

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

    9. 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
    10. Repeat the above step for remaining properties: FirstName, LastName and PhoneNumber.

      MDK

      Click Finish. The action editor will open with the Customers_UpdateEntity.action loaded.

      You can find more details about Update Entity Action.

    11. When the above OData action is executed, you may want to display messages on its success and failure behavior. For example, on its success, you may want to close the page and allow any execution to continue. On its failure, you may want to display an error.

      In the Customers_UpdateEntity.action, scroll down and expand the Common Action Properties section. Click the Create a rule/action icon for the Success Action.

      MDK
    12. Keep the default selection for the Object Type as Action and Folders path.

      MDK
    13. Choose UI in Category | click Close Page | Next.

      MDK
    14. In the Base Information, provide the below information and then click Finish to complete the action creation process.

      Property Value
      Name CloseModalPage_Complete
      DismissModal Select Completed from the dropdown
      CancelPendingActions Select false from the dropdown
      MDK
    15. Similar, create a message action displaying error in case of the update failure. In the Customers_UpdateEntity.action, click the Create a rule/action icon for the Failure Action.

      MDK
    16. Keep the default selection for the Object Type as Action and Folders path.

      MDK
    17. Choose Message in Category | click Message | Next.

      MDK
    18. In the Base Information, provide the below information and then click Finish.

      Property Value
      NameUpdateCustomerEntityFailureMessage
      Type Select Message from the dropdown
      Message Failed to Save Customer Updates - {#ActionResults:update/error}
      Title Update Customer
      OKCaption OK
      OnOK --None--
      CancelCaption leave it blank
      OnCancel --None--
      MDK

      Customers_UpdateEntity is the Action Result value of the Customers_UpdateEntity.action. This reference is used to pass the results to subsequent actions in the chain. These actions can reference the action result as needed. In this case if there is a failure, you access the error property of the action result to display the OData failure message.

      This is the standard Binding Target Path (also called Dynamic Target Path) syntax used when you need to include a binding with other bindings or within a string as used in the message here.

      You could exclude above expression and can just display a generic message.

    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.

    What is the ReadLink value set in Customers_UpdateEntity.action?

  • Step 4

    You will navigate from the Customer Detail page to a new page modifying customer information. For this, you will add an action bar item on the Details page and will link it to a navigation action. When the action bar item is pressed by the end-user that will open the Customers_Edit.page.

    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. Navigate to the Events tab. Click the 3 dots icon for the OnPress property and select the Create a rule/action.

      MDK
    4. Keep the default selection for the Object Type as Action and Folders path.

      MDK
    5. Choose UI in Category | click Navigation | Next.

      MDK
    6. Provide the below information:

      Property Value
      Action NameNavToCustomers_Edit
      PageToOpen Select Customers_Edit.page from the dropdown
      ModalPageSelect true from the dropdown
      MDK
    7. Click Finish to complete the action creation process.

  • Step 5

    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 6

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


Back to top