Skip to Content

Invoke oData expand from SAPUI5 controller

Hello,

I want to invoke the following oData url from SAPUI5 controller.

/EmpSet('453233')/?$expand=EmpDetails

I am aware of oData model concepts and how to invoke normal read using oData model. However, I am struggling to invoke the above url with the value 4533233.

As far as I understood, I can invoke expand query using

oModel1.read("/EmpSet", {
    urlParameters: {
        "$expand": "EmpDetails"
    }
});
How can I pass the value 453233 in the above code snippet..

Regards
Faddy
Add comment
10|10000 characters needed characters exceeded

  • Also, please note that I have used the following code, however it never hit the _fGetSuccess or _fGetError methods.

    oModel1.read( "/EmpSet('453233')", {

    urlParameters: {"$expand": "EmpDetails"},

    success: jQuery.proxy(this._fGetSuccess, this), error: jQuery.proxy(this._fGetError, this) } );

  • Get RSS Feed

4 Answers

  • Best Answer
    Jan 09 at 04:52 AM

    The code looks intact in my view.

    As it never hits _fGetSuccess or _fGetError methods, can you check whether those methods are declared correctly in the controller? Or try to embed the success/error method within the read() method and see what happens

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 08 at 01:14 PM

    Hello,

    This is strange, it should be working like you wrote in your comment. Is the EmpSet is really an EntitySet ? (dumb question, but who knows ... ? ;) )

    Regards,

    Joseph

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 08 at 06:52 PM

    Hello Fahad,

    If you open this query on a browser (give me all products where category is 1), it works:

    http://services.odata.org/OData/OData.svc/Categories(1)/?$format=json&$expand=Products

    So if you are able to open the following on your browser, your query must be correct:

    http://<server>:<port>/EmpSet(453233)/?$format=json&$expand=EmpDetails

    If it works on your browser, then it is a matter of calling the same on your controller. Have you tried this:

    var emp_id = "453233";
    oModel1.read("/EmpSet" + "(" + emp_id + ")", {
        urlParameters: {
            "$expand": "EmpDetails"
        }
    });

    I believe "453233" is a numeric value to your odata service. If not, please add single-quotes to your variable.

    Regards,
    Ivan

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 09 at 07:35 AM

    Thanks everyone for your valuable suggestions.

    Issue was that the method _fGetSuccess was misspelled in controller. It works now

    Add comment
    10|10000 characters needed characters exceeded