cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reset OData entity changes with Mobile Development Kit possible?

1,752

Hello everyone,

it is possible to reset changes of an OData OfflineStore Entity while working with the Mobile Development Kit?

For example, there is a OData OfflineStore Entity called "Order" and there are changes of this entity. Now the editor of the entity will reset the changes of the entity "Order" before synchronizing the OData OfflineStore. Is there a Mobile Development Kit OData Action type or API functionality to archieve this?

Maybe you can help me.

Thanks!

Accepted Solutions (1)

Accepted Solutions (1)

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Likes

thomasschilling

Do you want to undo the local changes done against "Order" entity?

If so, you can use Offline OData UndoPendingChanges action

0 Likes

Hi Jitendra,

this is the proper Action I was searching for.

Is there also a functionality to retrieve all entities with pending changes?

For example there is a functionality which retrieves the following Offline OData entities with pending changes (UPDATE, CREATE, DELETE):

  • OrderSet('ID1')
  • OrderSet('ID2')
  • DefectSet('ID1')
  • CheckListItemSet('ID1')
  • CheckListItemSet('ID2')
  • CheckListItemSet('ID3')

With this list of entities I will process for each entity the Action UndoPendingChanges.

Thank you!

Answers (1)

Answers (1)

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert
0 Likes

thomasschilling

UndoPendingChanges action can only undo 1 entity at a time, so it's up to application how you want to handle undoing the pending changes for more than one entity and also for other entitysets.
You can leverage @sap.isLocal property from the Offline OData to understand the state of the record in an EntitySet, it is set to true when record was created/updated locally and has not been synced to the backend yet.

for example, in a Customers list page, i am updating an existing record and also creating a new one, i can call this rule on the list page that will loop through each customer items (have been locally created and updated) and undo the changes.


export default function UndoAllChanges(context) {
    return context.read('/MyTestingApp/Services/SampleServiceV2.service', 'Customers', [], `$filter=sap.islocal()`).then((results) => {
        if (results && results.length > 0) {
            console.log("length" + results.length);
            let promiseList = [];
            results.forEach(item => {
                console.log("Item" + item);
                let updatePromise = context.executeAction({
                    "Name": "/MyTestingApp/Actions/Customers/UndoLocalChanges.action",
                    "Properties": {
                        "Target": {
                            "EditLink": item['@odata.readLink']
                        }
                    }
                })
                promiseList.push(updatePromise);
            });
            Promise.all(promiseList).then(() => {
                message = `undo local changes worked fine`
                return context.executeAction({
                    "Name": "/MyTestingApp/Actions/GenericToastMessage.action",
                    "Properties": {
                        "Message": message

                    }
                })
            })
        }
        else {
            message = `No local changes available`;
            return context.executeAction({
                "Name": "/MyTestingApp/Actions/GenericToastMessage.action",
                "Properties": {
                    "Message": message
                }
            });
        }
    });
}

For undoing a deleted entity, you can first store it's readLink e.g. in ClientData once item has been deleted and then execute undoing it in a rule.
You can follow this approach for other EntitySet(s) and can handle doing for all in a single rule.

fjcarrasco
Active Participant

Hello jitendrakumar.kansal I'm a bit confuse because bill.froelich in this question:

https://answers.sap.com/questions/13292120/mdk-exception-attempting-to-update-a-downloaded-en.html

talked about sap.isLocal and sap.hasPendingChanges properties.

According to bill.froelich explanation, only property sap.hasPendingChanges is true when entity is updated locally:

"So for a newly created record both @sap.isLocal and @sap.hasPendingChanges will be true. For a downloaded record that has been updated only @sap.hasPendingChanges would be true."

However in your post:

"You can leverage @sap.isLocal property from the Offline OData to understand the state of the record in an EntitySet, it is set to true when record was created/updated locally and has not been synced to the backend yet."

Can you clear up this please ?

Thanks

Regards,

Kiko