I am trying to generate a batch request for the creation of two entities: a Parent entity and a Child entity belonging to that parent. For the linkage between them I want to use OData Content-ID header. I generate the request by this:
this.model.create("/ParentSet", {
Id: "000777000",
Store: "16"
}, {
error: function (errormessage) {
alert("create error" + JSON.stringify(errormessage));
},
headers: {
"content-ID": 1
}
});
this.model.create("/$1/ToChild", {
Id: "131313",
Area: ""
}, {
error: function (errormessage) {
alert("create error" + JSON.stringify(errormessage));
}
});
When executed from the web sapui5 application the code results in the creation of the correct request payload:
--batch_a8d1-2414-ee3e
content-type: multipart/mixed; boundary=changeset_0f62-99e1-b9a4
--changeset_0f62-99e1-b9a4
content-type: application/http
content-transfer-encoding: binary
POST ParentSet HTTP/1.1
content-ID: 1
sap-contextid-accept: header
Accept: application/json
Accept-Language: en-GB
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: UrrKfxCwzgpBlY8GVgtdWg==
Content-Type: application/json
Content-Length: 31
{"Id":"000777000","Store":"16"}
--changeset_0f62-99e1-b9a4
content-type: application/http
content-transfer-encoding: binary
POST $1/ToChild HTTP/1.1
sap-contextid-accept: header
Accept: application/json
Accept-Language: en-GB
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: UrrKfxCwzgpBlY8GVgtdWg==
Content-Type: application/json
Content-Length: 48
{"Id":"131313","Area":""}
--changeset_0f62-99e1-b9a4--
--batch_a8d1-2414-ee3e
content-type: application/http
content-transfer-encoding: binary
GET ParentSet/$count HTTP/1.1
sap-cancel-on-close: true
sap-contextid-accept: header
Accept: text/plain, */*;q=0.5
Accept-Language: en-GB
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: UrrKfxCwzgpBlY8GVgtdWg==
--batch_a8d1-2414-ee3e
content-type: application/http
content-transfer-encoding: binary
GET ParentSet?$skip=0&$top=100 HTTP/1.1
sap-cancel-on-close: true
sap-contextid-accept: header
Accept: application/json
Accept-Language: en-GB
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
x-csrf-token: UrrKfxCwzgpBlY8GVgtdWg==
--batch_a8d1-2414-ee3e--
However, when executed from the Cordova based SAP HAT application, the content-id header is placed to the change set instead to the Parent entity like that:
--batch_709b8b9352ac4342a0efb1e012d_1
content-type: multipart/mixed; boundary=changeset_709b8b9352ac4342a0efb1e012d_2
--changeset_709b8b9352ac4342a0efb1e012d_2
content-type: application/http
content-transfer-encoding: binary
content-id: 1
POST ParentSet HTTP/1.1
Content-Type: application/json
Accept: application/json;q=1, application/atom+xml;q=0.5
accept-language: en-US
sap-contextid-accept: header
{"Id":"000777000","Store":"16"}
--changeset_709b8b9352ac4342a0efb1e012d_2
content-type: application/http
content-transfer-encoding: binary
POST $1/ToChild HTTP/1.1
Content-Type: application/json
Accept: application/json;q=1, application/atom+xml;q=0.5
accept-language: en-US
sap-contextid-accept: header
{"Id":"131313","Area":""}
--changeset_709b8b9352ac4342a0efb1e012d_2--
--batch_709b8b9352ac4342a0efb1e012d_1--
Does anyone have any suggestion of how this problem can be solved so that the content-id header gets attatched correctly to the Parent entity and not to the change set?
The problem was solved by changing the offline configuration in SAP CP Mobile Services. Under Mobile Application > Native/Hybrid > Info > Assigned Features > Offline > Configuration you need to click on the edit button. In the popup-menu the Content ID Header Location had to be set to "Operation" instead if "Mime".