Skip to Content
avatar image
Former Member

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

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)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Feb 05 at 04:34 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 29 at 03:16 PM

    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?

    Add comment
    10|10000 characters needed 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.

  • Jan 29 at 02:52 PM

    Hi,

    Share your view code and network screenshot.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 29 at 03:02 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 29 at 03:18 PM

    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:

    Add comment
    10|10000 characters needed 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)?

  • May 10 at 01:00 PM

    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

    Add comment
    10|10000 characters needed characters exceeded