Skip to Content

Batch request offline oData

Hi,

I am trying to develop a mobile application that performs CRUD operations in the offline mode. I am using the Kapsel Offline OData plugin and I have created the application using Web IDE. When I am trying to perform an update, the application works for the online mode, but when I am trying in the offline mode, the operation performs but I don't see any request queue created on my local device. Also when I am online and trying to perform the flush and refresh operation, nothing happens. Could you please give me a hint on how should I perform the flush and refresh operation? I have the following code:

if (devapp.isOnline === true) {			var oModelOnline = new sap.ui.model.odata.ODataModel(sURl + "/fetchData.xsodata");
			var oEntryUpdateBUT000 = {};
			var oEntryUpdateADRC = {};
			var batchChange = [];
			oEntryUpdateBUT000.NAME_FIRST = this.getView().byId('myAccountFirstName').getValue();
			oEntryUpdateBUT000.NAME_LAST = this.getView().byId('myAccountLasttName').getValue();
			oEntryUpdateBUT000.PERSNUMBER = this.getView().byId('myAccountUserID').getValue();
			oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountRole').getValue();
			oEntryUpdateBUT000.BU_GROUP = this.getView().byId('myAccountMobile').getValue();
			oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountStreet').getValue();
//			oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountStreetNumber').getValue();
			oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountZIP').getValue();
			oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountCity').getValue();
//			oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountCity').getValue();
			oEntryUpdateADRC.MC_STREET = this.getView().byId("MyAccountStreet").getValue();
			
			batchChange.push(oModelOnline.createBatchOperation("/BUT000(PARTNER='" + 'ADVISOR' + "',CLIENT='" + '10'+ "')", "MERGE", oEntryUpdateBUT000));
			batchChange.push(oModelOnline.createBatchOperation("/ADRC(NATION='" + '' + "',CLIENT='" + '10'+ "',DATE_FROM=" + 'datetime' +"'" + '2000-01-01' + "',ADDRNUMBER='" + '0000011433' + "')", "MERGE", oEntryUpdateADRC));
			
oModelOnline.addBatchChangeOperations(batchChange);
oModelOnline.submitBatch(function(oResponse) {
oModelOnline.refresh();
	if (oResponse['__batchResponses'][0].message == "HTTP request failed") {
	  that.getMessageBox('001','warning',oView);
							
	} else {
	  that.getMessageBox('001','success',oView);
	}
			 
	 }, function(err){
									        alert("Batch submit failed");
			       });
			}

else if (devapp.isOnline === false) {
  var oModelOffline = new sap.ui.model.odata.v2.ODataModel(sURL+ "fetchData.xsodata");
 oModelOffline.setUseBatch(true);
var oEntryUpdateBUT000 = {};
var oEntryUpdateADRC = {};
var mParameters = {"groupID": "updateBatch",
		   "changeSetId": "updateBatch"};					
oEntryUpdateBUT000.NAME_FIRST = this.getView().byId('myAccountFirstName').getValue();
oEntryUpdateBUT000.NAME_LAST = this.getView().byId('myAccountLasttName').getValue();
oEntryUpdateBUT000.PERSNUMBER = this.getView().byId('myAccountUserID').getValue();
oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountRole').getValue();
oEntryUpdateBUT000.BU_GROUP = this.getView().byId('myAccountMobile').getValue();
oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountStreet').getValue();
oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountZIP').getValue();
oEntryUpdateBUT000.BU_GROUP = this.getView().byId('MyAccountCity').getValue();
				
oEntryUpdateADRC.MC_STREET = this.getView().byId("MyAccountStreet").getValue();
				
oModelOffline.update("/BUT000(PARTNER='" + 'ADVISOR' + "',CLIENT='" + '10' + "')", oEntryUpdateBUT000, mParameters);
				oModelOffline.update("/ADRC(NATION='" + '' + "',CLIENT='" + '10' + "',DATE_FROM=" + 'datetime' + "'" +'2000-01-01' + "',ADDRNUMBER='" + '0000011433' + "')", oEntryUpdateADRC, mParameters);

oModelOffline.submitChanges(
		jQuery.proxy(function(oData, oResponse) {
		if (oResponse && oResponse.statusCode === 201) { // 201 == Created
		if (oData && oData.__metadata && oData.__metadata.id) {
							var idx = oData.__metadata.id.lastIndexOf("/");
									var bindingPath = oData.__metadata.id.substring(idx);
								}
							}
						}, this),
	jQuery.proxy(function(error) {
				var msg = error;
	if (typeof(error) === "object" && error.response && error.response.body) {
	msg = error.response.body;
							}
	this._showServiceError(msg);
						}, this)
					);

Regards,

Iolanda

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

0 Answers