Skip to Content
0

Invoke oData expand from SAPUI5 controller

Jan 08 at 11:25 AM

57

avatar image

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
10 |10000 characters needed characters left 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) } );

0
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
avatar image
Former Member Jan 09 at 04:52 AM
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

Share
10 |10000 characters needed characters left characters exceeded
Joseph BERTHE Jan 08 at 01:14 PM
1

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

Share
10 |10000 characters needed characters left characters exceeded
Ivan Mirisola
Jan 08 at 06:52 PM
1

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

Share
10 |10000 characters needed characters left characters exceeded
SAP Learner Jan 09 at 07:35 AM
0

Thanks everyone for your valuable suggestions.

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

Share
10 |10000 characters needed characters left characters exceeded