cancel
Showing results for 
Search instead for 
Did you mean: 

Init funtion called twice and causes Odata service to be called twice

yasser_aoujil
Explorer
0 Kudos

Hi,

I have a problem with an oataModel bounded to a table, in a Fiori app with XML based views, that's being called twice in the init funtion. I have seen this thread, and this one, none of them is answered in a way it could help me.

Under I provide the screenshots of google network tab, also the code of the init function, and when I put the breakpoints in the beginning of the init, it simply stops twice.

I hope someone could help me or guide me to a possible cause/solution, as this is pretty fast in test environment, but in production, the first call is pretty fast, but the second one takes like 20 seconds to complete, and meanwhile leaves the user awaiting.

The chrome network tab, after the repeated calls are completed and everything is showing fine:

The XML view of table bound to the oDataModel EXPSet

The init function in the controller:

onInit: function() {
			var sServiceUrl, oModel;
			this.oModelI18n = new sap.ui.model.resource.ResourceModel({
				bundleUrl: "i18n/i18n.properties"
			});
			sServiceUrl = this.oModelI18n.getResourceBundle().getText("webServiceURL");
			oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true, "{i18n>user}", "{i18n>pass}");
			oModel.setHeaders({
				"Access-Control-Allow-Origin": "*"
			});
			this.getView().setModel(oModel);
                        //Filter Odata services
			var oView = this.getView();
			this.filtroGlobal = [];
			this.filtroEmbudo = [];
			oModel.read("FiltroDetSet?$filter=Columna eq 'Contratista'", null, null, false, function(oData, oResponse) {
				var oModelCont = new JSONModel(oData.results);
				oView.setModel(oModelCont, "contratistas");
			});
                        //Coordinadas
			oModel.read("FiltroDetSet?$filter=Columna eq 'Coordinador'", null, null, false, function(oData, oResponse) {
				var oModelCoor = new JSONModel(oData.results);
				oView.setModel(oModelCoor, "coordinadores");
			});
			//Poblaciones
			oModel.read("FiltroDetSet?$filter=Columna eq 'Poblacion'", null, null, false, function(oData, oResponse) {
				var oModelPob = new JSONModel(oData.results);
				oView.setModel(oModelPob, "poblaciones");
			});
			//Directores de obra
			oModel.read("FiltroDetSet?$filter=Columna eq 'Director'", null, null, false, function(oData, oResponse) {
				var oModelDir = new JSONModel(oData.results);
				oView.setModel(oModelDir, "directores");
			});
			//Estados de obra
			oModel.read("FiltroDetSet?$filter=Columna eq 'Estado'", null, null, false, function(oData, oResponse) {
				var oModelEst = new JSONModel(oData.results);
				oView.setModel(oModelEst, "estados");
			});
			this._propiedadATextoCol = function(prop) {
				if (prop === "Name1") {
					return "Contratista";
				} else if (prop === "Poblacion") {
					return "Población";
				} else if (prop === "Name2") {
					return "Dir.Obra";
				}
			};
			this._GroupByField = null;
			this.mGroupFunctions = {
				Name1: function(oContext) {
					var name1 = oContext.getProperty("Name1");
					return {
						key: name1,
						text: name1
					};
				},
				Poblacion: function(oContext) {
					var poblacion = oContext.getProperty("Poblacion");
					return {
						key: poblacion,
						text: poblacion
					};
				},
				Name2: function(oContext) {
					var name2 = oContext.getProperty("Name2");
					return {
						key: name2,
						text: name2
					};
				}
			};
		}

Accepted Solutions (0)

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

if your view is initialized twice, how can you blame odatamodel.....

you need to provide more info about how your app is coded/structured

yasser_aoujil
Explorer
0 Kudos

Hi Jun,

I am new to SAP Fiori so can you tell me more info on what should I provide about the structure of the app?