Several changeset in one request payload when submitChanges execute
Hello guru's,
I am using OData model v2, i've got a table with some records (sap.m.table), and I want to modify a field in more than one record, when I call method submitChanges and see the payload and I realize that each record from my entity was include diferents changeset and batch groups, when in my code I ensure that only use one batchgroup and change set id. I also see that any of the names of the changeset is the same I defined. My idea is to process all the records sent to the backend but not independently, I use CHANGESET_BEGIN and CHANGESET_END.
--batch_d0dc-21c0-39f6 Content-Type: multipart/mixed; boundary=changeset_34fd-02a8-22c4
--changeset_34fd-02a8-22c4 Content-Type: application/http Content-Transfer-Encoding: binary
MERGE ApprCategorySet(RowIid='0012',AppraisalId='DE791B89280C1EE4BAD79409CF1ED44A') HTTP/1.1 Accept: application/json Accept-Language: es-419 DataServiceVersion: 2.0 MaxDataServiceVersion: 2.0 x-csrf-token: AiP09zm0osLOCW9m16G1kg== Content-Type: application/json Content-Length: 425
{"RowIid":"0012","AppraisalId":"DE791B89280C1EE4BAD79409CF1ED44A","ForeignId":"00000293","ForeignType":"","ItemText":"Realizar labores de riego por aspersión y gravedad.","WeightingEnabled":"X","PartialGradeEnabled":"X","FinalGradeEnabled":"X","Weighting":"1","PartialGrade":"0.000","FinalGrade":"0.000","TxtPartialGrade":"","TxtFinalGrade":"","ParentIid":"0006","__metadata":{"type":"ZHCM_PERF_EVAL_SERV_SRV.ApprCategory"}} --changeset_34fd-02a8-22c4--
--batch_d0dc-21c0-39f6 Content-Type: multipart/mixed; boundary=changeset_88f3-53fa-9719
--changeset_88f3-53fa-9719 Content-Type: application/http Content-Transfer-Encoding: binary
MERGE ApprCategorySet(RowIid='0013',AppraisalId='DE791B89280C1EE4BAD79409CF1ED44A') HTTP/1.1 Accept: application/json Accept-Language: es-419 DataServiceVersion: 2.0 MaxDataServiceVersion: 2.0 x-csrf-token: AiP09zm0osLOCW9m16G1kg== Content-Type: application/json Content-Length: 454
{"RowIid":"0013","AppraisalId":"DE791B89280C1EE4BAD79409CF1ED44A","ForeignId":"00000294","ForeignType":"","ItemText":""Ejecutar controles de malezas quimicos y manuales en suertes, acequias y corona","WeightingEnabled":"X","PartialGradeEnabled":"X","FinalGradeEnabled":"X","Weighting":"3","PartialGrade":"0.000","FinalGrade":"0.000","TxtPartialGrade":"","TxtFinalGrade":"","ParentIid":"0006","__metadata":{"type":"ZHCM_PERF_EVAL_SERV_SRV.ApprCategory"}} --changeset_88f3-53fa-9719--
--batch_d0dc-21c0-39f6--
Could you please kindly help me with this theme?
Best regards.
Jhon Jairo Teran
Hello Jhon,
the batchGroup definition for this TwoWay changes is different to the ones for reading data. You normally want to read data via non deferred group, but want to submit the changes via deferred group. All changes on an entity via TwoWay binding will be collected per default in a deferred batchGroup with the name 'changes'. Per default every change get it's own ChangeSet. The batchGroups for TwoWay changes could be defined with the setChangeBatchGroups function of the ODataModel. Please see the API documentation for more details.
You could define a batch group per EntityType (or '*' for all EntityTypes). Setting the single flag to false enforces one ChangeSet for all changes. So in your case the following the call following should do the trick:
yourModel.setChangeBatchGroups({"*":{batchGroupId:"myChanges", single: false }}); ... myModel.submitChanges("myChanges");
If you want to bundle other manual requests (create/remove/update/delete) with your property changes you have to use the default 'changes' batchGroupId or the one you defined via setChangeBatchGroups.
BR, Jan
Thanks for your reply Jan, now setting single = false I could put all my table changes in only one changeset. Now I would want to reflect this changes inmediatelly when I delete or create rows, please I ask for your help to do this, because when I add (oDataModel.createEntry()) or delete (oDataModel.remove()), this changes doesn't reflect automatically on my view, what do I have to do?
Kind regards.
Jhon Jairo Teran.
Hello Jhon,
TwoWay binding is only supported for property changes yet. The entity created with createEntry could not be added to the table directly. You have to create the entity at the backend and afterwards you need to refresh the ággreagtionBinding of the table. The same applies for removing entities from your table. The refresh could be done with our automatic refresh (refreshAfterChange) which is per default turned on. The model detects which bindings are affected by your changes and triggers an automatic refresh within the batch request of the changes. So you have to submit your created/removed entities first to get the changes visible at your table.
BR, Jan
Proposal given, no reply.