cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

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

0 Kudos
1,308

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.

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
SAP Champion
SAP Champion
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