cancel
Showing results for 
Search instead for 
Did you mean: 

Create new entry in the ODataModel

xyla
Participant
0 Kudos

Hello All,

After creating the ODataModel (sap.ui.model.odata.v2.ODataModel), I want to create in the model a new entry of a specific entity, and bind it to my controls, so the user can fill the attributes. This is what I do:


var oCtx = this.modelRef.createEntry("/OrderDetailGeneralSet", null);

  oControl = this.getView().byId("GeneralOrderDataFragment");

  oControl.setBindingContext(oCtx);

There is no entry created in the oData node of the model. What am I doing wrong?

Thanks,

Szilamér

Accepted Solutions (1)

Accepted Solutions (1)

santhu_gowdaz
Active Contributor
0 Kudos

I don't know what's wrong in your code. But oData model is using for server side model(Getting data from server or post data to server) and JSON model is using as client side model. So better you create a JSON model(and also it's so easy to create an entity and having more properties).

xyla
Participant
0 Kudos

The whole thing is much more complex. The bottom line is that i have to use ODataModel...

santhu_gowdaz
Active Contributor
0 Kudos

I created new entry as below,

var oModel = sap.ui.getCore().getModel("ModelRef");

  var oCtx = oModel.createEntry("/ExistingCollection/NewEntry"); 

  console.log("oCtx>"+oCtx);

xyla
Participant
0 Kudos

Thanks a lot!

xyla
Participant
0 Kudos

One more question: How can I bind this new entry to my controls?

I can't use bindElement(), because in that case the model tries to request the data from the server for this new entry.

I tried setBindingContext(), with the returned context from createEntry(), but if I modify the value of my controls, it is not reflected in the model.

santhu_gowdaz
Active Contributor
0 Kudos

i can see in debug mode, the new entry structure is as same as the "ExistingCollection".

so may be you can see those values in "/ExistingCollection/NewEntry/PropertyName" path,

xyla
Participant
0 Kudos

I'm looking in the debugger too. you're right about the structure. The new entry is created with the structure of the given entity.But the properties of the new entry stay "undefined" despite the modification of the value on the UI.

And then there is the question: where are the new values saved, if not in the (new entry of) model?

0 Kudos

I am facing the same problem with the UI not updating the model. Where you able to find a solution?

Answers (0)