Skip to Content

How to populate a Combo Box dynamically from the results of an OData reading?

Hi there.

I've build a Fiori App which is intended to show a VizChart-based chart. But to get the source data to display the chart, some filters are needed. The thing is that the available options of that filters have to be got, at the same time, from the backend system.

On the XML View, I've declared a vertical box inside of which is the combo box which I intend to fill from an OData reading:

<p:Label id="peopleLabel" text="Developer" design="Bold"></p:Label>
<p:ComboBox id="developers" busy="false" visible="true" enabled="true" editable="true"
showValueStateMessage="true" textAlign="Initial" textDirection="Inherit" maxWidth="100%">

I think my problem is the condition of syncrhony inherent to any version 2 of OData reading. On the JS control corresponding to the XML View above I've coded the following:

var oDevelopers = this.getView().byId("developers");
var ServiceURL = "/sap/opu/odata/sap/ZOM_QA_ABAP_SRV";
var oModelRead = new sap.ui.model.odata.v2.ODataModel(ServiceURL);
var entity = "/PerformanceEvolutionAxisSet";
var oFilters = [];
var Field1 = new sap.ui.model.Filter({
path: "System",
operator: sap.ui.model.FilterOperator.EQ,
value1: "System_1"
var oDataRead = {
User: "", 
Developer: "" 
function fnSuccess(oDataR, oResponse) { 
oDataRead = oDataR; 
function fnError(oError) {
}, {
filters: oFilters, 
success: fnSuccess(),
error: fnError }); 
oModelRead.attachRequestCompleted(function() {}

The use of the Attach Requested Completed event, as I understand, is intended to perform actions which needs the results of the reading. And obviously, this is that case.

But my question is, how can I access to the oDevelopers reference from within the function attached to the Request Completed event, in order to add the items to the combo box?

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Jan 10, 2018 at 03:41 AM

    did you try?????

    I don't think you need to do anything, just reference ti.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 10, 2018 at 12:21 PM

    Hi Jun. Oh, yes, yes I've tried ineed. Except the oDataRead reference, which is populated with the oDataR reference inside the fnSuccess function, I can't access to any reference declarated outside the event from within it.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 10, 2018 at 05:01 PM

    Hi Ignacio,

    Did you see this example already?

    I believe that all you are missing is define your combobox with the "items" property bound to your model's property.


    Add comment
    10|10000 characters needed characters exceeded

  • Jan 10, 2018 at 07:03 PM

    Well... It's a good moment for you and everybody else to know that I'm nothing but an ABAP developer; all (the few) things I've learned about JS I've learned them on basis of seeing (and debugging thanks to the F12 Console Chrome tool) examples.

    I had already seen that example. But as I can understand, the model there is a JS file. In my case, which would be the model? Would it be the oModelRead reference? If so, due to its fields are not "key" and "text" fields (neccesary in order to be bound to a Combo Box items list), how can I transform it accordingly? And last, but not least, where should I bound the items with the model? In the XML View or in the JS Control?

    Add comment
    10|10000 characters needed characters exceeded