cancel
Showing results for 
Search instead for 
Did you mean: 

Invoke oData expand from SAPUI5 controller

fahad_saplearning
Participant
0 Kudos

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
fahad_saplearning
Participant
0 Kudos

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) } );

Accepted Solutions (1)

Accepted Solutions (1)

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

Answers (3)

Answers (3)

Ivan-Mirisola
Product and Topic Expert
Product and Topic Expert

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

Joseph_BERTHE
Active Contributor

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

fahad_saplearning
Participant
0 Kudos

Thanks everyone for your valuable suggestions.

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