cancel
Showing results for 
Search instead for 
Did you mean: 

Update of an Entity does not update data after create entity

Angelo_Ab
Participant
0 Kudos
124

Hi,

I have a problem during the update of Offline entity with backend errors.

I have two Entity:

  • Header
  • Items

During creation of Sales Order I Sync to Backend a ChangeSet with two Create Operations for both Header Data and Items. If the ChangeSet does not throws Errors all were synced and saved correctly to backend. If the ChangeSet throws Errors the Order is stored in the Offline Store with @SAP.inErrorState=true and @SAP.isLocal=true.

 
For example, the error is a missing attribute in one of the item.
 
When I try to Change affected Order Item I use another ChangeSet with two Update Operations for both Header and Items. The Operations are both with Replace(PUT) UpdateMode.
 
When I sync data again, the backend do not receive the changed attributes but seems to receive the same data of Creation. (I checked the backend Trace)
 
Instead of that, Offline Store seems correctly updated with changed attributes.
 
Example:
Creation:
Item.TypePos = "TANN"
Backend receive "TANN"
 
Update
Item.TypePos = "TAN"
Backend receive "TANN"
Offline Store contains "TAN"
 
This is the ChangeSet Action Code:
 
{
    "_Type": "Action.Type.ODataService.ChangeSet",
    "ActionResult": {
        "_Name": "ChangeSetUpdateSalesOrder"
    },
    "OnFailure": "/app/Rules/CreateSalesOrder/ChangeSetUpdateSalesOrderFail.js",
    "OnSuccess": "/app/Actions/ClosePageAndSync.action",
    "Target": {
        "Service": "/app/Services/ServiceV2.service"
    },
    "Actions": [
        "/app/Actions/EditSalesOrder/UpdateSalesOrderHeader.action",
        "/app/Rules/EditSalesOrder/UpdateSalesOrderItems.js"
    ]
}
 
This is the Update Items Rule Code:
 
import Utility from "../Utility/Utility";
/**
 * Describe this function...
 * @param {IClientAPI} clientAPI
 */
export default async function UpdateSalesOrderItems(clientAPI) {

  //get page proxy
  let pageProxy = clientAPI.getPageProxy();

  //get Application Client Data
  let applicationClient = pageProxy.getAppClientData();

  //get items
  let items = pageProxy.getAppClientData().Items;
  if (items) {
    for (var i = 0; i < items.length; i++) {
      items[i].OrderS = Utility.getHeaderPageKey(clientAPI);
      pageProxy.setActionBinding(items[i]);
      if (items[i].isNew && items[i].isNew === true) {
        await clientAPI.executeAction("/app/Actions/CreateSalesOrderActions/CreateSalesOrderItems.action");
      } else {
        if (applicationClient.isOrderLocal) {
          await clientAPI.executeAction("/app/Actions/EditSalesOrder/UpdateSalesOrderItems.action");
        } else {
          await clientAPI.executeAction("/app/Actions/CreateSalesOrderActions/CreateSalesOrderItems.action");
        }
      }

    }
  }
  return Promise.resolve();

}
 This is the Update Items Action Code:
{
    "_Type": "Action.Type.ODataService.UpdateEntity",
    "ActionResult": {
        "_Name": "UpdateSalesOrderItems"
    },
    "Target": {
        "Service": "/app/Services/ServiceV2.service",
        "EntitySet": "ItemSet",
        "ReadLink": "{@odata.readLink}"
    },
    "Properties": {
        "Delete": "{Delete}",
        "DiscountPos": "{DiscountPos}",
        "Discount": "{Discount}",
        "OrderS": "{OrderS}",
        "Posnr": "{Posnr}",
        "Matnr": "{Matnr}",
        "RefHigh": "{RefHigh}",
        "EAN": "{EAN}",
        "CustMaterial": "{CustMaterial}",
        "ShipTo": "{ShipTo}",
        "Qty": "{Qty}",
        "UM": "{UM}",
        "DataCons": "{DataCons}",
        "Tester": "{Tester}",
        "Value": "{Value}",
        "Url": "{Url}",
        "Storage": "{Storage}",
        "TypePos": "{TypePos}",
        "Plant": "{Plant}",
        "DescriptionMat": "{DescriptionMat}",
        "AddItem": "/app/Rules/Application/Conversion/ConvertItemAddItem.js",
        "DiscScale": "{DiscScale}"
    },
    "RequestOptions": {
        "RemoveCreatedEntityAfterUpload": true,
        "UpdateMode": "Replace"
    }
}
 
What is wrong ?
 
Thank you.
 
 

Accepted Solutions (1)

Accepted Solutions (1)

Angelo_Ab
Participant

After reading a lot of the MDK Help Guides I found the solution:

https://help.sap.com/doc/f53c64b93e5140918d676b927a3cd65b/Cloud/en-US/docs-en/guides/features/offlin...

After reverting the errors in Error Archive I was able to send a new Change Set request to backend.

Without this procedure, the ChangeSet Fails because of dependent requests.

Error like: This request was not executed because it depended on request (N).

Answers (0)