Skip to Content
0

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

Jan 29 at 02:19 PM

267

avatar image
Former Member

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 !!

empty-list.png (1.5 kB)
object-list.png (69.1 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

6 Answers

Sagarika Gattu Feb 05 at 04:34 AM
1

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

Share
10 |10000 characters needed characters left characters exceeded
Jun Wu Jan 29 at 03:16 PM
0

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?

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

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.

0
Irfan Gokak Jan 29 at 02:52 PM
0

Hi,

Share your view code and network screenshot.

Share
10 |10000 characters needed characters left characters exceeded
Efim Parshin Jan 29 at 03:02 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Jan 29 at 03:18 PM
0

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:


network.png (108.3 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

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)?

0
Nagarajan S May 10 at 01:00 PM
0

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

Show 1 Share
10 |10000 characters needed characters left characters exceeded

here plantuser is name of the model.

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

0