on 08-03-2015 6:53 PM
I have an Odata service with getEntity and getEntitySet methods implemented for an Employee entity. The following screenshot shows the xml output of getEntity in browser.
Now from the same method , I want to populate a text field in UI5 with the value of "Name" . For that I created oDATA model instance but I m not able to understand how to call a single entity. I tried with SAP Demokit but in all the examples , they dont show the sample XML data from which they are extracting the data making it difficult to understand which xml tags and path they are binding to an element. Hence I am not getting a clue on how to achieve my above requirement using getEntity .
createContent : function(oController) {
var oData = new sap.ui.model.odata.ODataModel("http://ehp7prd.sap.in:8200/sap/opu/odata/sap/ZEMPLOYEE_SRV/",false,"fioriconfig","Bharath123");
//oData.read("EmplSet('002')");
sap.ui.getCore().setModel(oData);
var oFlowLayout = new sap.ui.layout.ResponsiveFlowLayout({
responsive : true // boolean
});
var inp1 = new sap.ui.commons.TextField("txt1");
inp1.bindProperty("value","/EmplSet('002')/Name");
anyhing in dev console?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Once again I refreshed the page , and this time metadata file was shown with 200 status and not 304 as shown above in screenshot.i
And one more important thing I missed to tell is that, i tried putting external breakpoint in my get_entity method and its NOT getting triggered. However if i uncomment the line //oData.read("EmplSet('002')");
then the breakpoint inside getEntity method is triggered. So that means link and connectivity issues are not there otherwise in case of oData.read would not have triggered the breakpoint.
Any soulutions people??
Regards
Is this helpful?
var oModel = new sap.ui.model.odata.ODataModel("http://ehp7prd.sap.in:8200/sap/opu/odata/sap/ZEMPLOYEE_SRV/");
sap.ui.getCore().setModel(oModel);
var inp1 = new sap.ui.commons.TextField("txt1");
var sRead = "/EmplSet(Empno='002')" ;
oModel.read( sRead, null, null, true, function(oData, oResponse){
inp1.setValue(oData.Name);
},function(){
alert("Read failed");});
Hi,
Thanks a lot for your reply. I will have the system access at night so I will be able to test it out that time and let you know the result. Meanwhile I got few doubts regarding your solution.
1)So in the above code . bindProperty method is not required??? If not then whats the difference between the two ways a) by usinng read b) by using bindProperty
2) Also according the to API reference for read method . following parameters can be passed .
read(sPath, mParameters?) : object
Parameters:
{string} | sPath | |
{map} | mParameters? | |
{object} | mParameters.context? | |
{map} | mParameters.urlParameters? | |
{boolean} | mParameters.async?, Default: true | true for asynchronous requests. |
{array} | mParameter.filters? | |
{array} | mParameter.sorters? | |
{function} | mParameters.success? | |
{function} | mParameters.error? |
In your above example when we pass the following parameters , the boolean parameter is passed as 4th parameter whereas in the above list its 5th parameter . So do we need to have an extra comma before that?? . Similarly after the boolean parameter there are 2 array parameters filters and sorters followed by the 2 functions , so in the code below do we need to have 2 commas before the function to indicate that we are not passing anything to the filters and sorters array.
I mean how the system is going to know which variable/object we are going to pass for which parameter if the sequence and no of parameters are not exactly same. Kindly let me know on this
oModel.read( sRead, null, null, true,function(oData, oResponse){
inp1.setValue(oData.Name);
},function(){
alert("Read failed");});
Thanks a lot
Here i checked that 2nd parameter is referring to below provided parameters.
{map} | mParameters? | Optional parameter map containing any of the following properties: |
Check this once and let me know for any issues.
Thanks everyone who helped me out here . Dhananjay and Seungchul , both your solutions worked for me . So i came to know now two of the ways by which u can retireve data for Odata
1) using read() function for oModel as shown by Dhananjay
2) using bindProperty as shown by Seungchul
So now just wanted to know which of these method to apply in which scenario and what is the preferred method to be used generally in odata out of these 2 and if any performance related things to be considered while deciding the same.
Many thanks everyone
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hallo Amber
Maybe you could try something like this for your model?
var idModel = new sap.ui.model.odata.ODataModel(myUrl, false);
idModel.read("employeeSet(filter1='x',filter2='y')",
null,
[],
true,
function(oData, oResponse) {
var empData = {
employee : oData.id,
};
var idModel = new sap.ui.model.json.JSONModel();
idModel.setData(empData);
sap.ui.getCore().setModel(idModel, "idDataModel");
},
function(oEvent) {
}
);
txfEmp = new sap.ui.commons.TextField().bindProperty("text", {path: "empData >/employee"});
Regards
Antonette
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
H Antonette,
Thanks a lot for your reply. I just have a slight concern here that is there anyway I can avoid using JSON model in the above case . Or can the above be written using XMLmodel instead of Json.
Also var idModel is declared twice , will it create any issues?
In this txfEmp = new sap.ui.commons.TextField().bindProperty("text", {path: "empData >/employee"});
the bindProperty would be on value or text since i want to bind the textfield value with this odata. And i guess /employee refers to entity name which in my case is /Empl so probably i will replace /Empl with /employee , right??
I will have access to system at night only hence I will be able to check all these that time only.
Regards
User | Count |
---|---|
81 | |
10 | |
10 | |
9 | |
7 | |
6 | |
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.