on ‎2021 Jul 15 7:51 AM
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!
Help others by sharing your knowledge.
AnswerRequest clarification before answering.
thomasschilling
Do you want to undo the local changes done against "Order" entity?
If so, you can use Offline OData UndoPendingChanges action
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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):
With this list of entities I will process for each entity the Action UndoPendingChanges.
Thank you!
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
| User | Count |
|---|---|
| 5 | |
| 5 | |
| 3 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.