Skip to Content

Batch request with submitChanges callback not called

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...

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Nov 18, 2016 at 05:04 AM

    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'.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 18, 2016 at 03:49 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 04, 2019 at 06:08 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.