cancel
Showing results for 
Search instead for 
Did you mean: 

Does data subscription work in an SAP MDK offline app ?

p619793
Active Participant
0 Kudos

Hi,

I have an SAP MDK offline app where I have an object table in a page showing a list of items. The object table has data subscription assigned to the entityset that was in the target binding. I have 'delete' button in the page which deletes the selected items in multiselect mode.

Page:

Rule:

/** * Describe this function... * @param {IClientAPI} clientAPI */export default async function DeleteFavoriteItems(context) { var sectionedTable = context.getControl("SectionedTable"); var section = sectionedTable.getSection("ItemsTable"); var selectedItems = section.getSelectedItems(); if (!selectedItems || selectedItems.length === 0) { context.executeAction({ "Name": "/PR_Reservation/Actions/BasicToast.action", "Properties": { "Message": "Nothing is selected" } }); } let result = null; if (selectedItems.length == 1) { result = await context.executeAction({ "Name": "/PR_Reservation/Actions/ConfirmAction.action", "Properties": { "Message": "$(L, ConfirmDeleteSingleMessage)" } }); } else { result = await context.executeAction({ "Name": "/PR_Reservation/Actions/ConfirmAction.action", "Properties": { "Message": "$(L, ConfirmDeleteMultipleMessage)" } }); } if (result && result.data) { let deleteFavoritePromises = []; for (var i = 0; selectedItems && i < selectedItems.length; i++) { var selectedItem = selectedItems[i]; deleteFavoritePromises.push(context.executeAction({ "Name": "/PR_Reservation/Actions/HeaderStrSet/DeleteFavoriteItem.action", "Properties": { "Target": { "ReadLink": selectedItem.binding["@odata.readLink"] } } })); // await context.executeAction({ // "Name": "/PR_Reservation/Actions/HeaderStrSet/DeleteFavoriteItem.action", // "Properties": { // "Target": { // "ReadLink": selectedItem.binding["@odata.readLink"] // } // } // }); } return Promise.all(deleteFavoritePromises).then(results => { deleteFavoritePromises = []; section.setSelectionMode("None"); return context.executeAction('/PR_Reservation/Actions/HeaderStrSet/DeletFavouriteMessage.action');
}); //context.getAppClientData().deleteFavoritePromises = deleteFavoritePromises; //section.redraw();
}}

Best regards,

Sumit

Accepted Solutions (0)

Answers (1)

Answers (1)

mingkho
Advisor
Advisor

Hi Sumit

Yes DataSubscription is supported for Offline OData too.

In your case, there's actually no need to explicitly add UserDetailsSet to the DataSubscription, that's because when you bind UserDetailsSet to your Object Table's Target > EntitySet, it will automatically be added to the Data Subscription of that Object Table.

p619793
Active Participant
0 Kudos

Hi ming.kho ,

I checked both with and without 'Data Subsciption' for the object table. But after deletion it doesn't remove the items from the list.

The request goes to backend alright and after sync the page refreshes perfectly. But we want the items removed visually on the page after deletion even before performing sync action.

Best regards,

Sumit

mingkho
Advisor
Advisor
0 Kudos

Which platform and what version of MDK are you using?

I tested your scenario and it works fine in both MDK 6.3.7 and 23.4.0

Did you check, after deletion if without performing sync action, you close and re-open the list page, are the deleted items disappear from the page? (This will help confirm that the items are indeed correctly removed from the local Offline database). If the deleted items are still there when you re-open the list page, then your issue is probably no longer related to data subscription but something else.

Also it might help to know what's in DeleteFavoriteItem.action and DeletFavoriteMessage.action

Regards

Ming

p619793
Active Participant
0 Kudos

Hi ming.kho ,

We are using MDK 6.3.7. I added a ClosePage action after delete action which closed the page and came back to the previous page. But when I went back to the list of favorites pae, the deleted item does not disappear. I forgot to mention before that the list page and delete actions are actually happening in a changeset action which was opened by a navigation action to a modal stack. Could that be a reason for it not to work?

/** * Describe this function... * @param {IClientAPI} clientAPI */export default async function DeleteFavoriteItems(context) { var sectionedTable = context.getControl("SectionedTable"); var section = sectionedTable.getSection("ItemsTable"); var selectedItems = section.getSelectedItems(); if (!selectedItems || selectedItems.length === 0) { context.executeAction({ "Name": "/PR_Reservation/Actions/BasicToast.action", "Properties": { "Message": "Nothing is selected" } }); } let result = null; if (selectedItems.length == 1) { result = await context.executeAction({ "Name": "/PR_Reservation/Actions/ConfirmAction.action", "Properties": { "Message": "$(L, ConfirmDeleteSingleMessage)" } }); } else { result = await context.executeAction({ "Name": "/PR_Reservation/Actions/ConfirmAction.action", "Properties": { "Message": "$(L, ConfirmDeleteMultipleMessage)" } }); } if (result && result.data) { let deleteFavoritePromises = []; for (var i = 0; selectedItems && i < selectedItems.length; i++) { var selectedItem = selectedItems[i]; deleteFavoritePromises.push(await context.executeAction({ "Name": "/PR_Reservation/Actions/HeaderStrSet/DeleteFavoriteItem.action", "Properties": { "Target": { "ReadLink": selectedItem.binding["@odata.readLink"] } } })); // await context.executeAction({ // "Name": "/PR_Reservation/Actions/HeaderStrSet/DeleteFavoriteItem.action", // "Properties": { // "Target": { // "ReadLink": selectedItem.binding["@odata.readLink"] // } // } // }); } return Promise.all(deleteFavoritePromises).then(results => { deleteFavoritePromises = []; section.setSelectionMode("None"); return context.executeAction('/PR_Reservation/Actions/HeaderStrSet/DeletFavouriteMessage.action').then(results => { return context.executeAction('/PR_Reservation/Actions/ClosePage.action') });
}); //context.getAppClientData().deleteFavoritePromises = deleteFavoritePromises; //section.redraw();
}}

DeleteFavoriteItem.action:

{ "_Type": "Action.Type.ODataService.DeleteEntity", "Target": { "Service": "/PR_Reservation/Services/com_hse_PR_Reservation.service", "EntitySet": "UserDetailsSet", "ReadLink": "{@odata.readLink}" }}

DeletFavouriteMeassage.action:

{ "_Type": "Action.Type.ToastMessage", "Message": "Selected Favourite items will be deleted on sync"}

Best regards,

Sumit

p619793
Active Participant
0 Kudos

Hi ming.kho , I rechecked with Close Modal Page action and the deleted item disappears when I go back to the list page which is expected.

Best regards,

Sumit

mingkho
Advisor
Advisor

Hi Sumit

That explains it, when inside a changeset action the delete operations doesn't actually happen until the changeset is completed (a.k.a committed) successfully, so in that situation you'd need to redesign your flow

Instead of changeset > navigate > modal list page > DeleteFavoriteItems

That means the changeset is won't be committed until the modal list page is closed as completed

It might be better to do:

Navigate > modal list page > changeset > "Actions": ["path/to/DeleteFavoriteItems.js"]

That means the changeset will be committed as soon as the DeleteFavoriteItems.js finished execution.