cancel
Showing results for 
Search instead for 
Did you mean: 

Data fetching from combo box using oDATA model into SAPUI5 in Java Script.

Former Member
0 Kudos

I have a SAPUI5 page developed in view.js and controller.js with having mutliple combobox controls in the SPAUI5 page.

Can anyone suggest,on how to get data for that particular combobox using odata model,i don't want any JSON included in between and i don't want to use view.xml in SAPUI5.

I have tired the way,but if i maintain the KEY and Text field values as blank,the i am getting list as [object Object] or else if fill any values in the KEY and Text field,i am getting the combo box as empty list as shown in the attached image,whereas here the count of empty list is same as columns in the Tables.

View.js:

var oComboBox_FunArea = new sap.m.ComboBox({ items:{ path: "/EntitySet_Name", template : new sap.ui.core.Item({ key:'{Table_Field_column_name}', text:'{value of the field}' }) };

Controller.js:

var sServiceUrl = ("proxy/http/____________:8000/sap/opu/odata/SAP/YREQSUB_SRV/");

var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl,true);

this.getView().setModel(oModel);

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

Can you please advise me,what does the KEY field in sap.core.item exactly required for and can i

maintain the same values in KEY and Text fields.

Please help me soon !!

Accepted Solutions (0)

Answers (6)

Answers (6)

sagarikagattu
Participant

Hello Vijay,

Yes you can give the same value for key an text, one of the use for key is for validation, if user enters any value in combo box, we can validate the value using key property.

Can you try the below code once?

this._oView = this.getView();

var OModel = this._oView.getModel("dataset");

sap.ui.getCore().setModel(OModel); //the model defined in manifesto

sap.ui.getCore().byId("combo").setModel(OModel);

var oItemTemplate1 = new sap.ui.core.ListItem();

oItemTemplate1.bindProperty("text", "Desg");

oItemTemplate1.bindProperty("key", "Desg");

sap.ui.getCore().byId("combo").bindItems("/DesignationSet", oItemTemplate1); //reference to the entityset

former_member309899
Participant
0 Kudos

Hi,

oCombo = new sap.m.ComboBox({filterSecondaryValues: "true", showSecondaryValues:"true", enabled:"{state>/comboPreventive}", width:"100%"});

oListItem = new sap.ui.core.ListItem({key:"{plantuser>EmployeeId}",text:"{plantuser>EmployeeName}"});

oCombo.bindItems("plantuser>/d/results",oListItem);

Regards,

Nagarajan S

former_member309899
Participant
0 Kudos

here plantuser is name of the model.

please replace "d/results" by your entityset name.

Former Member
0 Kudos

Hi Irfan/All,

Pls. find the view code for that particular dropdown and network screenshot

View.js:

var oComboBox_FunArea = new sap.m.ComboBox({ items:{ path: "/TESTFA2Set", template : new sap.ui.core.Item({ key:"{FunArea}", text: "{MM}"})

Network:

former_member233511
Participant
0 Kudos

I'll suggest again that you use deprecated version of OData model. Use V2.

And can you provide payload of request to your set (with mock data)?

junwu
Active Contributor
0 Kudos

why you are so against json model and xml view?

js view should always be your second option.....

{Table_Field_column_name} is it a field under the entity?

Former Member
0 Kudos

Hi Jun,

It's not like that, i am aganist,but the thing we have developed all the View in JS and we ahve data in ODATA model,so want to pull data into view.

> {Table_Field_column_name} is it a field under the entity?

yes,it's under the entityset and able to see the data init in ODATA model.

former_member233511
Participant
0 Kudos

Hello again! Why do you use deprecated version of ODataModel? Use sap.ui.model.odata.v2.ODataModel instead. And settig model to Core it's bad practice. Setting model on view will be enough.

irfan_gokak
Contributor
0 Kudos

Hi,

Share your view code and network screenshot.