on 05-07-2018 11:32 AM
Hello Experts,
Could someone help me with my below query? Thanks in advance 🙂
Consider the below odata service
d: { results: [{ __metadata: { type: "", uri: "", }, ID: 1001,
Name: "SAP",
Address: "Germany",
Phone: "43230986"}
When I make a call to the odata from my view.xml as,
<Text text= {ID} />
<Text text= {Name} />
<Text text= {Address} />
<Text text= {Phone} />
I get my output as ,
1001 SAP Germany 43230986
Is there a way, where I can consume the key itself from the odata?
As in, I should get my output as,
ID Name Address Phone
Hi Shiny,
"I am looking for something of this way, where I can access the metadata via view.xml. I refer to
It depends on the Odatamodel namespace and UI version which is used. Please refer the API reference for OdataModel
https://sapui5.hana.ondemand.com/#/api/sap.ui.model.odata.ODataModel
In Namespace sap.ui.model.odata and namespace sap.ui.model.odata.v2, method getServiceMetadata is available. If UI version is greater than equal to 1.38, you can use v2 namespace. In the above link which is shared by you, refers the ODATA.V2 namespace, inorder to use it, UI version should match and metadataLoaded event should be trigger to fetch ServiceMetadata else the method return value as undefined as shown below.
If namespace sap.ui.model.odata(Deprecated) is used, We can use the same method getServiceMetadata to fetch the entitytype fields assigned in metadata.
"URL
var surl = "/sap/opu/odata/sap/ZGW_SO_SRV/";
"Model
var oModel = new sap.ui.model.odata.ODataModel(surl, true);
By navigating the below path, you can fetch the entity property name
var meta = oModel.getServiceMetadata();
var name1 = meta.dataServices.schema[0].entityType[0].property[1].name
Check the detailed path for service metadata in console Output as shown below
Regards
Rajkumar Narasimman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
use the method read
//Step 1: get instance of model (assuming model name as 'myModel' as defined in manifest.json)
var oModel = this.getOwnerComponent().getModel('myModel');
//Step 2: read data from model(assuming entity set name as 'myEntity' with key field as 'ID')
oModel.read("/myEntity(ID='1001')", {
success: function(oData, response){
console.log(oData); //this contains data
},
error: function(oError ){
console.log("Error in reading Data:", oError);
}
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Shiny,
Use getServiceMetadata to read the Metadata information from the model.
https://www.sap.com/developer/tutorials/xsa-sapui5-metadata.html
Regards
Rajkumar Narasimman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Raj... 🙂
I am looking for something of this way, where I can access the metadata via view.xml. I refer to https://sapui5.hana.ondemand.com/#/sample/sap.ui.table.sample.OData2/code/View.view.xml.
Any help on this?
Shiny
User | Count |
---|---|
94 | |
11 | |
11 | |
10 | |
9 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.