cancel
Showing results for 
Search instead for 
Did you mean: 

oModel.read is not working.

former_member593030
Participant

Hello All,

I am using Webide,

So In Controller my oModel.read is not getting data from Backend system.

Please find my code here. Any suggestion?

onInit: function () {
var sServiceUrl = "/sap/opu/odata/sap/ZUI_USERCREATION_SRV/";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
this.getView().setModel(oModel); 
var oJsonModel = new sap.ui.model.json.JSONModel();
oModel.read("/CostCenterSet",{ success: function(oData, response){
            oJsonModel.setData(oData);
            sap.ui.getCore().setModel(oJsonModel);
            
}
});
},

Accepted Solutions (0)

Answers (3)

Answers (3)

AbhishekSharma
Active Contributor
0 Kudos

Hi Sujoy,

You might want to try sending key field as parameter because you are using Read method. Please take reference from below code.

You also need to update your odata method to get this parameter and pass to backend code.

onPressRead:function(){
			var oView = this.getView();
			var fnm = oView.byId("txtFNM1").getValue();
			var oModel = new sap.ui.model.odata.v2.ODataModel("/sap/opu/odata/sap/ZEMP_SRV/");
			var sPath = "/EmpSet(Empfnm='"+ fnm +"')";
			
			oModel.read(sPath, {
				success: function(oData){
					MessageToast.show(oData.Empfnm + "-----" + oData.Emplnm);
				},
				error: function(oData){
					MessageToast.show("Error");
				}
			});
		},

For Console Information :

When you use Chrome (recommended Browser) press F12 and you will see developer tools panel will be displayed..

Hope this helps...

Thanks-

Abhishek

maheshpalavalli
Active Contributor
0 Kudos

It would have been more helpful if u had pasted the error log from browser console..

But before that, I can see u r instantiating the odata model in Ur init method.. What I would suggest is to use the manifest.json to instantiate Ur odata model.. In manifest.json. Also, I hope if u r using cloud webide u r using cloud connector or if u r using local webide, u need to create destination files.. else while connecting to backend it gives "same origin" error..

Best regards,

Mahesh

maheshpalavalli
Active Contributor
0 Kudos

In browser click f12 and u can see console log there..

junwu
Active Contributor
0 Kudos

with this information....no one can help.

did you debug? did it reach your odata service?

what the console say?.....

former_member593030
Participant
0 Kudos

Hi Jun,

How Can i get Console value here?

Console statement is not allowed in webide.