Skip to Content
0

Issues with SAPUI5 v2 oData Model: setProperty()

Aug 14, 2017 at 08:38 AM

251

avatar image
Former Member

HI friends,

I'm using the SAP Web IDE version 160128 (local installation).

For update backend data I'm trying to use deffered groups, but unfortunately I faced an issue.

I want to collect all user input changes and then submit them on Save button click.

So, code sample from controller:

var oModel = this.getView().getModel();

oModel.setUseBatch(true); // Enable batch

oModel.setRefreshAfterChange(false); // Ban of refresh after change

oModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay); // Set RwoWay binding mode as default

oModel.setChangeGroups({ //Set change group

"AgentSet": { groupId: "grpId", changeSetId: "chgId", single: false }

});

oModel.setDeferredGroups(["grpId"]); // Set group as deffered

Sample from my XML view:

<Input id="description"

value="{

path: 'Description',

mode: 'TwoWay',

parameters: { groupId: 'agnhdr', changeSetId: 'chgId' }

}"

liveChange="onICC"

change="onInputChange"/>

Creating of new entry works fine, there are no request:to backend:

oModel.createEntry("/AgentSet", {

properties: { Id: "", Description: "New entry" },

groupId: "grpId",

changeSetId: "chgId"

});

But when I change Input field of existing entry (or call method oModel.setProperty() for One way binding mode) it is directly sending an Batch request to backend without calling SubmitChanges()

So, could anybody help me to solve this issue? I didn't find any info about possible extra settings (except setDeferredGroups()) for deferred update.

Also callback functions "Success" and "Error" doesn't trigger on submit changes:

oModel.submitChanges({

success: function(oData, oResp){

console.log(oData); console.log(oResp);

}, error: function(oError){ console.log(oError);

groupId: "grpId"

});

To solve last I'm using attachment of event "requestCompleted", but I don't like this solution:

oModel.attachEventOnce("requestCompleted", null, function(oEvt){

console.log(oEvt.getParameters());

if (oEvt.getParameters().response.responseText){

var oResp = JSON.parse(oEvt.getParameters().response.responseText);

}

console.log(oResp);

var oData = oView.getBindingContext().getObject(); console.log(oData);

});

Hope someone could help me

BR,

Boris

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

1 Answer

Best Answer
avatar image
Former Member Aug 15, 2017 at 10:57 AM
1

Found my mistake!

I should point the entity TYPE name, NOT entity SET here:

oModel.setChangeGroups({

"AgentSet": { groupId: "grpId", changeSetId: "chgId", single: false }

});

Share
10 |10000 characters needed characters left characters exceeded