cancel
Showing results for 
Search instead for 
Did you mean: 

skip user id and password while running app for getting data from Odata into JSON model

Former Member
0 Kudos

Hi All,

By one of the tutorial, I could able to get Products data by using the url :

var sUrl = "http://services.odata.org/Northwind/Northwind.svc/Products";  Here, userid and password are not  given and able to get data.

In the same way, I want to get data from a custom table using the following register service.

  var sUrl = "http://x.y.com:8020/sap/opu/odata/sap/Z_LEAVE_CRUD_SRV/zleave_reqSet";

In this case, when I am trying to access data from my system, I thing we should give user id and password. So what code should be added to the follwoing or can we skip the authentication and get data as public access.

1. var sUrl = "http://services.odata.org/Northwind/Northwind.svc/Products";

2. var oModel = sap.ui.model.json.JSONModel(sUrl);

3. sap.ui.getCore().setModel(oModel);

4. this.getView().setModel(oModel);

How should I replace line 1, with my registered service url (http://x.y.com:8020/sap/opu/odata/sap/Z_LEAVE_CRUD_SRV/zleave_reqSet )

* either i want skip authentication or which code should be written to give user id and password so as to get data

Thanks,

Srinivas

Accepted Solutions (0)

Answers (1)

Answers (1)

vijay_kumar49
Active Contributor
0 Kudos

Try this code.

var createUrl = "/sap/opu/odata/sap/ODataService ";

var createQuoteModel = new sap.ui.model.odata.ODataModel(createUrl, true,"userName", "Password");

sap.ui.getCore().setModel(createModel, " createModel ");

this.getView().byId("KDGRP_id").bindElement("/EntitySets('Provide your Input Values')");

Former Member
0 Kudos

HI Vijay,

Can we convert the model data into JSON, equivalent of var oModel = sap.ui.model.json.JSONModel(sUrl);

Thanks,

vijay_kumar49
Active Contributor
0 Kudos

U means Convert OData into JSON Mode?

If yes, We can convert.

onInit():

  1. var sServiceUrl = this.getUrl("/sap/opu/odata/sap/Z_MY_SERVICE_SRV/"); 
  2. var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl,true,"user","pass");        
  3. oModelJson = new sap.ui.model.json.JSONModel(); 
  4. oModel.read("/Items", null, ["$filter=ImItems eq 'imputParameter'"], null, function(oData, oResponse){  
  5.    oModelJson.setData(oData); 
  6. }, null ); 
  7. sap.ui.getCore().setModel(oModelJson, "myModel"); 

createContent():

  1. new sap.m.DisplayListItem ({ 
  2.     label: "My label"
  3.     value: "{myModel>/results/0/Property}"
  4. }),     

Regards

Vijay