Skip to Content

oData V4 create entity

Mar 30 at 01:53 PM


avatar image


how do I create a new entity with oData V4 model without having an existing ListBinding?

I have a SimpleForm and want to create a new entity based upon the entered information.

So I tried to manually create a ListBinding as this seems to be the only way to create a new enitty via create() method.

var oListBinding = oModel.bindList("/Templates");
var oContext = oListBinding

But nothing is being sent to the backend.

What am I doing wrong?

All examples I have found base upon a control being bound and used a syntax like this

var oListBinding = this.getView().byId("mainmenulist").getBinding("items");
var oContext = oListBinding


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Mathias Uhlmann
Apr 05 at 12:17 PM

Hi Oliver,

the request is created only when the respective updateGroup is submitted. Please see the

Sales Orders sample in the demokit for an example how the creation of a new record could be handled. The request is sent to the backend when the user saves.

  onSaveSalesOrder : function () { 
   * Submits the given batch group while the view is locked.
   * @param {string} sGroupId
   *   the group ID
  submitBatch : function (sGroupId) {
   var oView = this.getView();
   function resetBusy() {
   oView.getModel().submitBatch(sGroupId).then(resetBusy, resetBusy);

Best regards

10 |10000 characters needed characters left characters exceeded
Oliver Unknown Apr 10 at 10:50 AM

Hi Mathias,

thanks, I now got it to work, adding entities works fine.

But unfortunatelly I'm unable to process potential errors as the Error Part is never executed.

            var oListBinding = oModel.bindList("/Templates", undefined, undefined, undefined, { $$updateGroupId: "AddTemplate" });
            var oContext = oListBinding
                    "global_tool_id": odd_tools.getSelectedKey(),
                    "template_name": otxt_template_name.getValue()

                function () {
                    MessageBox.alert(oView.getModel("i18n").getResourceBundle().getText('AddTemplateSuccessMessage') + ' ' + oContext.getProperty("id") + ".", {
                        icon: MessageBox.Icon.SUCCESS,
                        title: oView.getModel("i18n").getResourceBundle().getText('Success')
                }, function (oError) {
                    MessageBox.alert(oView.getModel("i18n").getResourceBundle().getText(oError.message), {
                        icon: MessageBox.Icon.ERROR,
                        title: oView.getModel("i18n").getResourceBundle().getText('Error')
            oModel.submitBatch("AddTemplate").then(resetBusy, resetBusy);

10 |10000 characters needed characters left characters exceeded