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
- How to delete a record in web application
You may clone an existing project from 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 3 dots icon for the
OnPress
property and select theCreate a rule/action
. -
Select the Object Type as Rule and keep the default Folders path.
You could link
OnPress
property 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. -
Enter the Rule name as
Customers_DeleteConfirmation
and click Finish to complete the rule creation process. -
Replace the generated code with below snippet.
JavaScriptCopyexport default function DeleteConfirmation(context) { return context.executeAction('/DemoSampleApp/Actions/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
DeleteConfirmation.action
andCustomers_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
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
DeleteConfirmation.action
:Field Value Message
Delete current entity?
Title
Delete Confirmation
OKCaption
OK
OnOK
--None--
CancelCaption
Cancel
OnCancel
--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.action
is executed. -
Similarly, fix the path reference for the missing
Customers_DeleteEntity.action
. Switch back to theCustomers_DeleteConfirmation.js
or 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 Service
Select SampleServiceV2.service
from the dropdownEntitySet
Select Customers
from the dropdownReadLink
click 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
readLink
is 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
, provide value as delete for the Action Result and click theCreate a rule/action
icon 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 Name
DeleteCustomerEntityFailureMessage
Type
Select Message
from the dropdownMessage
Delete entity failure - {#ActionResults:delete/error}
Title
Delete Customer
OKCaption
OK
OnOK
--None--
CancelCaption
leave it blank OnCancel
--None--
delete is the Action Result value of the
Customers_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.action
gets executed successfully thenCloseModalPage_Complete.action
will be triggered or ifCustomers_DeleteEntity.action
fails thenDeleteCustomerEntityFailureMessage.action
will be triggered.Which component distributes the Mobile Development Kit (MDK) metadata to the MDK Mobile client?
- Step 3
Deploy the updated application to your MDK client.
Right-click
Application.app
and select MDK: Deploy.Select deploy target as Mobile & Cloud.
You should see success message for both deployments.
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.
- 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 com.sap.mdk.demo | Mobile Connectivity | click Launch in Browser icon
It will open the URL in a new tab, remove
?auth=uaa
and add/Customers
at the end of the URL.What is the ActionResult value set in the Customers_DeleteEntity.action?