Skip to Content
0

SAPUI5 OData read doesn't work properly

Feb 27 at 07:51 AM

122

avatar image

Hi altogether,

I am writing my first own list report based on SAPUI5 with SAP Web IDE in SCP. I am Standing at the point, getting the data from my own odata-service from backend. The following coding doesn't give back the data in the oData-Object.

Setting a breaktpoint in backend, get_entityset is called correctly and the data is wirtten to et_entityset. If i call the service manually per URL in browser, it works perfect and gives back the data in XML format. What seems a little bit strange to me: in network tab of development tools, I can't see the GET request I expect.

What am i missing or doing wrong?

thanks in advance and best regards

Christian

jQuery.sap.declare("Z_HCM_CICO_REP.Component");
jQuery.sap.require("sap.ui.generic.app.AppComponent");
jQuery.sap.require("sap.ca.scfld.md.ComponentBase");

sap.ui.generic.app.AppComponent.extend("Z_HCM_CICO_REP.Component", {
metadata: { 
	"manifest": "json" 
	}
});
sap.ui.define([
"sap/ui/core/UIComponent",
"sap/ui/Device"
], function(UIComponent, Device) { 
	"use strict";
 	return UIComponent.extend("Z_HCM_CICO_REP.Component", {

 /**  * The component is initialized by UI5 automatically during the startup of the app and calls the init method once.  * @public  * @override  */ 
	init: function() { 
		// call the base component's init function
		UIComponent.prototype.init.apply(this, arguments);
		this.getRouter().initialize();
		var oResourceModel = new sap.ui.model.resource.ResourceModel({
			bundleName: "Z_HCM_CICO_REP.i18n.i18n"
		});
			sap.ui.getCore().setModel(oResourceModel, "i18n");
 			
			//load cicos
			var sServiceUrl = "/sap/opu/odata/sap/ZHCM_CICO_REP_SRV/";
			var oModel = new sap.ui.model.odata.v2.ODataModel(sServiceUrl, true);
			var oJsonModel = new sap.ui.model.json.JSONModel(); this.setModel(oModel);
 			
			oModel.read("/TimeEntrySet", null, null, false, function(oData, oResponse) {
				oJsonModel.setData(oData);
				sap.ui.getCore().setModel(oJsonModel);
			} 
		);
	});
});
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Vaibhav Maheshwari Feb 27 at 08:58 AM
0

hi Christian,

The syntax of the model.read method being used is incorrect.

You have declared a odata.v2.ODataModell whereas you are using syntax for older version of odata.OdataModel.

Please use the new syntax and your code should work as expected.

https://sapui5.hana.ondemand.com/1.44.23/#docs/api/symbols/sap.ui.model.odata.v2.ODataModel.html#read

oModel.read("/TimeEntrySet", {
success : function(oData, oResponse) {
				oJsonModel.setData(oData);
				sap.ui.getCore().setModel(oJsonModel);
			} ,
error : function(oError) {
				// Error Handling Here
			} 

});

Thanks,

Vaibhav Maheshwari

Share
10 |10000 characters needed characters left characters exceeded
Christian Köhler Feb 27 at 09:47 AM
0

Hi Vaibhav,

thank you. I corrected the coding, but the problem still persists. I attached a picture that shows, that oData is undefined. Could I have something wrong in the other parts of the application e. g. in manifest.json?

cusersg430401desktopodata-undefined.png

best regards

Christian


Show 2 Share
10 |10000 characters needed characters left characters exceeded

Hi Christian,

You are trying to check the value of oData when the service has not yet been called and the variable is not yet in scope therefore you are getting the undefined message.

Put a break point at line no. 44 as per our attached screen shot and you should be able to see the data if our service returns it properly.

Thanks,

Vaibhav

1

Hi Vaibhav,

indeed it was a handling mistake from myself. Setting the break point in line 44 shows the correctly filled oData-variable. What I don't understand: Why wasn't it filled in my first approach, setting the break point before and then jump manually over the function call with F10 in Chrome development tools?

thanks and best regards

Christian

0