Skip to Content
0

Reading OData Entity Set into Array - Its Blank! Why?

Dec 07, 2017 at 10:44 PM

49

avatar image

Hi:

I'm reading an SAP OData Entity Set for Purchase Order Line Items into an array. Works perfectly fine.


Then, secondarily, I'm reading another OData Entity Set into another array and then setting that as a model to a Dropdown Box, which I then add as a Column to my original table, the PO Line Items.

//OData to Array
var i_cb_tax_t = [];
l_odata_model.read( "/PO_Tax_Type_ES", { 
    success: function ( o_event ) {
        $.each( o_event.results, 
            function ( i, item ) {
                i_cb_tax_t.push( {
                    "key":  item.TAX_T,
                    "text": item.TAX_T } );
} ) } } );

//Array to a Model. Then the Model is set to the Dropdown Box to give it data.
l_cb_model        = new sap.ui.model.json.JSONModel( i_cb_tax_t );
l_col_label       = new sap.ui.commons.Label( { text: "Tax Type" } );
l_col_template_cb = new sap.ui.commons.DropdownBox( {
                        items: {
                            path:     '/',
                            template: new sap.ui.core.ListItem( {
                                key:  '{key}',
                                text: '{key}'
                            } )
                        },
                        displaySecondaryValues:  true
                    } );

//Give the Dropdown Box data by setting it to a Model, the Array
l_col_template_cb.setModel( l_cb_model );
i_pooli2.addColumn( new sap.ui.table.Column( {
    label:    l_col_label,
    template: l_col_template_cb,
    width:    "90px"
} ) );

And this also works perfectly fine, but only if I put an alert() statement or set a break-point in the browser right after the above code.

If I do not, the Dropdown Box will be blank, the array I_CB_TAX_T will be blank and I have no idea why?

Its as though the program ignores this code if I'm not looking at it. Like, "when a tree falls in the forest and no one is there to hear it, does it make a sound"? Silly, but that's what's happening here.

If I execute the code through, the secondary array has no data, but if I set up the break-point or put an alert statement right after it does, and behaves perfectly.

What do I need to do, to make this code register? I tried a "wait time" command to no effect.

Thanks,

Sean

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Sean Machado Dec 08, 2017 at 12:04 AM
0

I answered my own question with a little more digging, but it was a problem I was having for quite a while.

l_odata_model.read( "/PO_Tax_Type_ES", { 
----async:   false,------------------------------------
    success: function ( o_event ) {
        $.each( o_event.results, 
            function ( i, item ) {
                i_cb_tax_t.push( {
                    "key":  item.TAX_T,
                    "text": item.TAX_T } );
} ) } } );

async: false,

By default, the Model Read is an asynchronous call, so I set that to false to make it synchronous. Essentially that means, wait for the Model.Read to finish before moving to the next statement.


Share
10 |10000 characters needed characters left characters exceeded