on 2015 Jan 11 4:40 PM
HI,
I am New to UI5 .i have created odata gateway service with function Import that will take single parameter as importing parameter and return the data in table.My problem is I am not getting how to consume data from function import in SAP UI5 and how i can display the returned data in ui5 table.
can Any Help me out regarding the issue.
Regards
LK
Hello LK,
if you are using the service with an ODataModel you can use function "callFunction" of the ODataModel to call a Function Import.
The function has several parameters which allow you to specify the required information. For a detailed description of the parameters please have a look to the API reference.
Here is a simple example:
oDataModel.callFunction("TestFunctionImport", // function import name
"POST", // http method
{"parameter1" : "value1" }, // function import parameters
null,
function(oData, response) { }, // callback function for success
function(oError){} ); // callback function for error
If the function import call was successful the "success callback function" is called. Within that you can access the returned data.
Regards,
Florian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sonali,
As Florian stated, when using the oDataModel.callFunction you must specify a callback function which will be invoked when the Function Import succeeds. The first parameter of this callback function is oData = a js object which contains the result. For this particular situation (in which the Function Import return value cardinality is 0..n or 1...n , i.e. a table) the oData object will have the following structure:
{
"d":
{
"__metadata":
{
"type":"Collection(<<complex type name>>)"
},
"results":
[
/* an array of data records */
]
}
}
So you will be interested only in oData.d.results array (which will contain the 'real' data retrieved from your backend system). My suggestion would be to create a sap.ui.model.json.JSONModel from this array and then use it for data binding within a list / table. You can do this directly inside the callback function's body. Example code:
var model = new sap.ui.model.json.JSONModel(oData.d.result);
var list = new sap.m.List();
list.setModel(model);
list.bindItems({
path : "/",
template : new sap.m.DisplayListItem({ label: "{name}" })
});
Here you can also see a working example based on the code above: http://jsbin.com/lofamamina/1/edit?html,output
Regards,
Serban
Hi!
Thanks for the answer 🙂 but the example code is not completely correct. This is the correct sintax:
oDataModel.callFunction("/TestFunctionImport", { // function import name
method: "POST", // http method
urlParameters: {"parameter1" : "value1" }, // function import parameters
sucess: function(oData, response) { }, // callback function for success
error: function(oError){ } // callback function for error
});
User | Count |
---|---|
71 | |
11 | |
10 | |
10 | |
10 | |
8 | |
7 | |
7 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.