Delete a Customer Record in an MDK App
- How to delete a customer record
- How to store changes locally on Mobile app and sync these changes with backend
You may clone an existing metadata project from the MDK Tutorial GitHub repository to start with this tutorial.

- Step 1
You will add an action bar item to the Customer Detail page called Trash and link it to an event.
-
In
Customers_Detail.page, drag and drop an Action Bar Item to the upper right 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).
-
Click the link icon to open the object browser for the System Item property.
Double click the Trash type and click OK.

-
Navigate to the Events tab. Click the dotted icon for the
OnPressproperty and select theCreate a rule/action.
-
Select the Object Type as Rule and keep the default Folders path.

You could link
OnPressproperty directly to OData delete action directly instead to this JavaScript file. Idea of linking to JavaScript file is to let you understand another way to achieve similar functionality. -
In the Basic Information step, enter the Rule name as
Customers_DeleteConfirmationand click Finish to complete the rule creation process.
-
Replace the generated code with below snippet.
JavaScriptCopy/** * Describe this function... * @param {IClientAPI} context */ export default function Customers_DeleteConfirmation(context) { return context.executeAction('/demosampleapp/Actions/Customers_DeleteConfirmation.action').then((result) => { if (result.data) { return context.executeAction('/demosampleapp/Actions/Customers_DeleteEntity.action').then( (success) => Promise.resolve(success), (failure) => Promise.reject('Delete entity failed ' + failure)); } else { return Promise.reject('User Deferred'); } }); }In above code there are references to
Customers_DeleteConfirmation.actionandCustomers_DeleteEntity.action, those don’t exist in your metadata project yet. You will create these actions in next steps.
-
In the above rule, double-click on the red line highlighting missing reference for
Customers_DeleteConfirmation.action. You will notice a bulb icon suggesting some fixes, click on it, selectMDK: Create action for this reference, and clickMessage Action.
-
Provide the below information in the
Customers_DeleteConfirmation.action:Field Value MessageDelete current entity?TitleDelete ConfirmationOKCaptionOKOnOK--None--CancelCaptionCancelOnCancel--None--
When user taps or clicks the Trash icon on the Customer Detail page, a message will be displayed to confirm if user wants to delete current record. On it’s confirmation,
Customers_DeleteEntity.actionis executed. -
Similarly, fix the path reference for the missing
Customers_DeleteEntity.action. Switch back to theCustomers_DeleteConfirmation.jsor open it again if it was closed. Double-click on the red line highlighting missing reference forCustomers_DeleteEntity.action. You will notice a bulb icon suggesting some fixes, click on it, selectMDK: Create action for this reference, and clickODataService DeleteEntity Action.
-
Provide the below information in the
Customers_DeleteEntity.action:Property Value ServiceSelect com_sap_edm_sampleservice_v4.servicefrom the dropdownEntitySetSelect Customersfrom the dropdownReadLinkclick link icon and double click readLink
This action will store deleted record locally for an offline application or delete directly back to the backed for online applications.
The
readLinkis a direct reference to an individual entity set entry.You can find more details about Delete Entity Action.
In general, there are two databases in a mobile offline store. What are those?
-
- Step 2
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 display a success message and allow any execution to continue. On its failure, you may want to display an error.
-
In the
Customers_DeleteEntity.action, scroll down and expand the Common Action Properties section. Click the link icon to open the object browser for the Success Action and bind it toCloseModalPage_Complete.action.
-
Create a message action for displaying a message in case deleting of a customer fails. In the
Customers_DeleteEntity.action, click theCreate a rule/actionicon for the Failure Action.
-
Keep the default selection for the Object Type as Action and Folders path.

-
In the Template Selection step, choose Message in Category | click Message | Next.

-
In the Base Information step, provide the below information:
Property Value NameDeleteCustomerEntityFailureMessageTypeSelect Messagefrom the dropdownMessageDelete entity failure - {#ActionResults:Customers_DeleteEntity/error}TitleDelete CustomerOKCaptionOKOnOK--None--CancelCaptionleave it blank OnCancel--None--
Customers_DeleteEntityis the Action Result value of theCustomers_DeleteEntity.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.
-
Click Finish to complete the action creation process.
When
Customers_DeleteEntity.actiongets executed successfully thenCloseModalPage_Complete.actionwill be triggered or ifCustomers_DeleteEntity.actionfails thenDeleteCustomerEntityFailureMessage.actionwill be triggered.
Which component distributes the Mobile Development Kit (MDK) metadata to the MDK Mobile client?
-
- Step 3
You will now deploy the updated project to your MDK client.
Click the Deploy option in the editor’s header area, and then choose the deployment target as Mobile Services .

- Step 4
Make sure you are choosing the right device platform tab above.
You can cross verify if this record has been deleted in the backend.
Backend URL can be found in Mobile Services Cockpit.
Mobile Applications → Native/MDK → click the MDK App myapp.mdk.demo → Connectivity → click Launch in Browser icon

It will open the URL in a new tab, remove
?auth=uaaand add/Customersat the end of the URL.What is the ActionResult value set in the Customers_DeleteEntity.action?