cancel
Showing results for 
Search instead for 
Did you mean: 

Batch request with submitChanges callback not called

Louis-Arnaud
Participant
0 Kudos

Hello,

I'm not expert on SAPUI5 but I already build Fiori Applications starting with the generated apps from SAP Webide. Maybe this is the reason I missed something, but this time I used the last version of FIORI template and it doesn't work as I expect.

Model is define in manifest.json :

		"models": {
			"i18n": {
				"type": "sap.ui.model.resource.ResourceModel",
				"settings": {
					"bundleName": "customerexpiredprices.i18n.i18n"
				}
			},
			"": {
				"dataSource": "mainService",
				"preload": true,
				"settings": {
					"defaultBindingMode": "TwoWay",
					"useBatch": true,
					"defaultCountMode": "Inline"
				}
			}
		},

I want to delete multiple lines of an entity, but I want to do it in one request, this is why I used submitChanges to call the batch request and handle the succes or error event from the submitChanges :

		onDeletePress: function(oEvent) {


			var self = this;


			//Get Model
			var oModel = this.getView().getModel();


			//get selected lines
			var oSelectedContextPaths = this.byId("idMaterialList").getSelectedContextPaths();


			//Call delete for every lines
			if (oSelectedContextPaths.length === 0) {
				MessageBox.error(this.getResourceBundle().getText("noSelection"));
			} else {
				oSelectedContextPaths.forEach(function(sPath) {
					this.remove(sPath);
				}, oModel);
			}


			this.getModel("detailView").setProperty("/busy", true);
			oModel.submitChanges({
				success: function(oData, sResponse) {
					MessageToast.show(self.getResourceBundle().getText("deleteConditionSuccess"));
					self.getView().getModel().refresh(true);
					self.getModel("detailView").setProperty("/busy", false);
				},
				error: function(oError) {
					self.getModel("detailView").setProperty("/busy", false);
				}
			});
		},

Neither Success nor error functions defined in submitChanges method are called. Althought if I attach success function in the remove method it is called but for every lines.

I didn't expected this behavior, and i'm pretty sure I did something similar before and the succes was called from the submitChanges.

Please help...

Accepted Solutions (1)

Accepted Solutions (1)

kammaje_cis
Active Contributor

I doubt if anything is happening at all when 'submitChanges' is called. Verify that in the Network tab.

When this.remove() is called, I suspect that 'Delete' is called there itself.

If you want 'submitChanges' to trigger the call, you need to make use of API 'setDeferredGoups'.

Answers (2)

Answers (2)

mokgavdilabs
Discoverer
0 Kudos

It is an old thread, but anyway:
A call to oModel.remove (without batchgroup) usually triggers a request right away. I personally think this is a bug..

Regards Morten

Louis-Arnaud
Participant
0 Kudos

Maybe I wasn't clear enough but yes there are batch request sent, but it doesn't seems that it is sent by the submitChanges method as I don't get the callback.

Anyway, thanks a lot, if I define my own deferred group, it works !

Looked like this :

			var self = this;


			//Get Model
			var oModel = this.getView().getModel();


			//get selected lines
			var oSelectedContextPaths = this.byId("idMaterialList").getSelectedContextPaths();
			
			//Define group ID
			oModel.setDeferredGroups(["priceDeleteGroup"]);


			//Call delete for every lines
			if (oSelectedContextPaths.length === 0) {
				MessageBox.error(this.getResourceBundle().getText("noSelection"));
			} else {
				oSelectedContextPaths.forEach(function(sPath) {
					this.remove(sPath, { groupId: "priceDeleteGroup"});
				}, oModel);
			}


			this.getModel("detailView").setProperty("/busy", true);
			oModel.submitChanges({
				groupId: "priceDeleteGroup",
				success: function(oData, sResponse) {
					MessageToast.show(self.getResourceBundle().getText("deleteConditionSuccess"));
					self.getView().getModel().refresh(true);
					self.getModel("detailView").setProperty("/busy", false);
				},
				error: function(oError) {
					self.getModel("detailView").setProperty("/busy", false);
				}
			});

What I still don't understand is why I didn't need this before. And i'm pretty sure it was working without explicitlly define the groupId.