on 07-08-2015 1:26 PM
Hello,
I have to set up an ODataModel for one of my tables. While I had some experience with JSONModel and XMLModel, this is the first time that I need to use the ODataModel.
What I have right now, it's a simple MDOQuery template that returns the entries from a database table . While for a really simple JSONMdel, I would use the Illuminator service with the QueryTemplate set to my MDOQuery file path, like this:
var oModel= sap.ui.model.json.JSONModel();
oModel.loadData("/XMII/Illuminator?QueryTemplate=path/to/my/MDOQuery&Content-Type=text/json");
I have issues, achieving the same thing for a ODataModel.
Now, starting with the 14.0v, there is an OData service for running query templates, as seen here:
http://help.sap.com/saphelp_mii140sp02/helpdata/en/44/2e1d2d42994aef85ef91e58db8c7c9/content.htm
Based on this documentation, I tried to create an sap.ui.mode.odata.ODataModel similar to how I create the client-side models like JSON,XML:
var odataModel = new sap.ui.model.odata.ODataModel("/XMII/IlluminatorOData/QueryTemplate?QueryTemplate=path/to/my/MDOQuery");
When using this approach, the following error it's logged on the console:
GET http://<server>:<port>/XMII/IlluminatorOData/QueryTemplate/$metadata?QueryTemplate=path/to/my/MDOQuery 500 (Internal Server Error)
As a constructor parameter, the ODataModel, expects an service url, so I'm not really sure that my approach it's correct. Would it be possible to initialize and ODataModel like this?
Thank you.
I will actually respond to this question myself, with a working snippet, of how I managed to make it run:
var oDataURL ="http://<server>:<port>/XMII/IlluminatorOData?QueryTemplate=path/to/my/MDOQuery";
var oModel = new sap.ui.model.odata.ODataModel(oDataURL, true);
This seems to correctly initialize the model, but tbh, I don't see any differences between this and the first version.
Now, in case other would have to do something similar, I allready binded this model to a table. The table holds the 15 rows, and when scrolled-down, the rest of the rows are fetched from the service:
var oTable2 = new sap.ui.table.Table({
visibleRowCount: 15,
threshold: 16,
});
var oMeta = oModel.getServiceMetadata();
var oControl;
for ( var i = 0; i < oMeta.dataServices.schema[0].entityType[2].property.length; i++) {
var property = oMeta.dataServices.schema[0].entityType[2].property[i];
oControl = new sap.ui.commons.TextField().bindProperty("value",property.name);
oTable2.addColumn(new sap.ui.table.Column({label:new sap.ui.commons.Label({text: property.name}), template: oControl}));
}
oTable2.setModel(oModel);
oTable2.bindRows("/Rowset(QueryTemplate='path/to/my/MDOQuery',RowsetId=1)/Row");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am trying to pass username and password with illuminatorOData service.
Can you help me how to do this?
Reason for Passing credentials in URL:
Currently when I am running in browser its asking for username,password separately.
In order to eliminate this popup I want to pass in URL Itself.
How to do that?
Please help.
Regards,
Hari
Hello,
Unfortunately, it has been a while since i last time had any contact with the SAP environment.
Fortunately, I remember that I myself hit the same issue. I found out, that if you pass the username and password in the request URL, it also pass the credential asking pages/popup.
Therefore, for my above example URL:
var oDataURL ="http://<server>:<port>/XMII/IlluminatorOData?QueryTemplate=path/to/my/MDOQuery";
you should add the following two parameters: "&IllumLoginName=" and "&IllumLoginPassword=". And it will look something like:
var oDataURL ="http://<server>:<port>/XMII/IlluminatorOData?QueryTemplate=path/to/my/MDOQuery&IllumLoginName=userNameHere&IllumLoginPassword=passwordHere";
Ofc, make sure that the URL will not be public or something, case in which, you obviously shouldn't use this method .
Hopefully, this will be of any help to you. Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
10 | |
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.