cancel
Showing results for 
Search instead for 
Did you mean: 

How to send unchanged fields of entity using the submitChanges() method

0 Kudos

We are using setProperty() method to change fields of an existing entity. These changes are collected for a batch submit using the setDeferredGroups() method. If we call submitChanges() later on, only changed fields and the keys are submitted to the backend OData Service. But we need to have all fields of the entity send back for processing in backend. How can that be achived?

This is how we collect changes:

oModel.setDeferredGroups(["myChanges"]);
oModel.setChangeBatchGroups({"*":{batchGroupId:"myChanges", single: false }});
oModel.setProperty(path + "/DepCode1", selectEl.getSelectedKey());
oModel.setProperty(path + "/DepCodeGroup1", "YCSNCS");

Then in a central onSave method the changed data is submitted:

		onSave: function(oEvent) {
			var that = this;
			var successHandler = function(errorEvent) {
				sap.m.MessageBox.success("Success", {
					title: "Success",
					initialFocus: null
				});
				that.getModel().refresh(true);
			};
			var errorHandler = function(successEvent) {
				sap.m.MessageBox.error("Error!", {
					title: "Success",
					initialFocus: null
				});
			};
			var oModel = this.getView().getBindingContext().getModel();
			if (oModel.hasPendingChanges()) {
				oModel.submitChanges({
					success: successHandler,
					error: errorHandler
				});
			}
		},

But if we check the data of the request in data provider class (/IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_PROCESS) in ABAP, we can only see the keys and the changed fields are send to the backend. For further processing of the data we would need also the unchanged fields, otherwise we would have to read the data again from backend tables which would be a massive overhead.

Joseph_BERTHE
Active Contributor
0 Kudos

Hi,

I don't understand, if the data shown to your user comes from the BE, and after a submitChange, if you have the object key, why do you need the request send to you all the data ? They ara all in you BE ?!

Regards,

Joseph

junwu
Active Contributor
0 Kudos

can you check the http request?

it is merge or put?

0 Kudos

The http request is of type "MERGE".
@Joseph: If we do not send all fields back, we have to refetch some of the data in the backend, which causes performance issues during processing.

Accepted Solutions (0)

Answers (2)

Answers (2)

miltonc
Product and Topic Expert
Product and Topic Expert

By default, when you call the submitChanges() method of the OData model, the Merge operation is used. The Merge operation sends only the fields that have been changed.

If you want to send all the fields during the SubmitChanges() method, then you need to change the default behavior to Put operation. You can do this in your manifest.json file when you are defining the model.

"": { "dataSource": "mainService", "preload": true, "settings": { "defaultUpdateMethod": "Put", "defaultOperationMode": "Server", "defaultBindingMode": "TwoWay" } }
former_member13323
Participant
0 Kudos

I would mark this answer as correct. But put should be capitalize 'PUT'. Otherwise you might run into this issue

junwu
Active Contributor
0 Kudos

by default, the framework will call getentity for you automatically, but I don't know the case when you process through CHANGESET_PROCESS