OData V2 Model - createEntry example - suggest doc improvement
OpenUI5 version: 1.44.9
Browser/version (+device/version): Chrome
URL (minimal example if possible): https://openui5.hana.ondemand.com/#docs/guide/6c47b2b39db9404582994070ec3d57a2.html#loio6c47b2b39db9404582994070ec3d57a2
I was implementing a database insert with createEntry method of OData V2 Model. If I call "createEntry" like in following Documentation example, the POST request is triggered automatically and doesn't wait at submitChanges or deleteCreatedEntry. I think this is an unexpected behavior.
// create an entry of the Products collection with the specified properties and values
var oContext = oModel.createEntry("/Products", { properties: { ID:99, Name:"Product", Description:"new Product", ReleaseDate:new Date(), Price:"10.1", Rating:1} });
// binding against this entity
oForm.setBindingContext(oContext);
// submit the changes (creates entity at the backend)
oModel.submitChanges({success: mySuccessHandler, error: myErrorHandler});
// delete the created entity
oModel.deleteCreatedEntry(oContext);
To make it work properly I added groupId property to the parameters and it was working as expected.
I think the documentation should be improved at least on these lines by adding groupId:
var oContext = oModel.createEntry("/Products", { "groupId":"createGroup", properties: { ID:99, Name:"Product", Description:"new Product", ReleaseDate:new Date(), Price:"10.1", Rating:1} });
oModel.submitChanges({groupId: "createGroup", success: mySuccessHandler, error: myErrorHandler});
It will save a lot of nerves :)
Bests, Dusan
For me it was the other way round...
groupId was set: Immediate POST-Request
groupId was not set: POST-Request only when submitChanges was called
Hello @DusanSacha,
Thank you for sharing this finding. I've created a internal incident 1770200096.
Regards, Marin
Hey,
please check this documentation about $batch and groupIds:
https://sapui5.hana.ondemand.com/#docs/guide/6c47b2b39db9404582994070ec3d57a2.html#loio6c47b2b39db9404582994070ec3d57a2
Per default a deferred group with id 'changes' is defined and all 'TwoWay' and createEntry operations use that group. Operations in a deferred group are never submitted automatically. YOu have to call submitChanges. Please check the groups defined in your model. If "groupId":"createGroup" is working I think you've overwritten the default group 'changes'.
BR, Jan