on 02-10-2015 8:24 AM
Hi ,
Require Help to understand how to pass a value through oData services to BAPI to fetch the required result.
Detail:
I am trying to create a mobile app in sapui5 where Im consuming a odata service(Net Weaver gateway)...which is linked to a BAPI,
To Fetch few records from the BAPI, the user in the front end have to input a value...
This value i have to pass through the odata services to the BAPI.
Please Share Your Valuable Comments.
Thanks,
Ashwin
Hi Ashwin,
I think you need to search and go through the available material first. There are n number of documents and posts which can help you in understanding the technology as well as getting you started in this field. This is just to encourage you to nail the problem at your end first.
The way we retrieve data from OData service is:
URI for Read: /sap/opu/.../ZMYSERVICE/MyEntitySet(Key1='Value1',Key2='Value2')
URI for Query: /sap/opu/.../ZMYSERVICE/MyEntitySet?$filter=filter1 eq 'value1' and filter2 eq 'value 2'
You can check the links provided in Venu's reply as well as other posts for UI5 specific code snippets.
Regards,
Ekansh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Eknash,
I have built my oData service to read a particular dataset based on the first options that you have suggested
URI for Read: /sap/opu/.../ZMYSERVICE/MyEntitySet(Key1='Value1',Key2='Value2')
my URI is /sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011930')
This is giving me the correct result in Gateway Client
<?xml version="1.0" encoding="UTF-8"?>
-<entry xml:base="http://XXX/sap/opu/odata/SAP/ZMM_EMP_SRV/"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xmlns="http://www.w3.org/2005/Atom">
<id>http://XXX/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011930')</id>
<title type="text">EmployeeSet('00011930')</title>
<updated>2015-11-24T06:37:44Z</updated>
<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" term="ZMM_EMP_SRV.Employee"/>
<link title="Employee" rel="edit" href="EmployeeSet('00011930')"/>
-<content type="application/xml">
-<m:properties>
<d:Empid>00011930</d:Empid>
<d:Empname>Alpha Barry</d:Empname>
<d:Empadd>New Jersey</d:Empadd>
<d:Empdes>ABAP ANALYST</d:Empdes>
</m:properties>
</content>
</entry>
However, when I try to fetch the same from SAPUI5 application as per the code given below it is giving me the error.
Uncaught TypeError: Cannot read property 'Empname' of undefined
Following is the controller code of my app.
onInit : function() {
var sServiceUrl = "/sap/opu/odata/SAP/ZMM_EMP_SRV";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl,true);
var oJsonModel = new sap.ui.model.json.JSONModel();
oModel.read("/EmployeeSet('00011930')",null,null,true,function(oData,repsonse){
oJsonModel.setData(oData);
var results = oJsonModel.getProperty("/results/0");
var empname = results.Empname;
alert ("Employee Name is" +empname);
});
sap.ui.getCore().setModel(oJsonModel);
},
However, when I change the read code of line 6 from
oModel.read("/EmployeeSet('00011930')",null,null,true,function(oData,repsonse)
to
oModel.read("/EmployeeSet",null,null,true,function(oData,repsonse)
I get the result of the whole data set.
The issue is how to fetch only selected record in the dataset?
Any help would be highly appreciated.
Regards,
Firoz.
Hi Ashwin,
I have debugged on Chrome console and it gives me the error that I mentioned earlier.
Uncaught TypeError: Cannot read property 'Empname' of undefined
Result of my oData model in Gateway Client in JSON format is as follows:
/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet?$format=json
{
"d" : {
"results" : [
{
"__metadata" : {
"id" : "http://XXX:8000/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011034')",
"uri" : "http://XXX:8000/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011034')",
"type" : "ZMM_EMP_SRV.Employee"
},
"Empid" : "00011011",
"Empname" : "Gamma",
"Empadd" : "King Street",
"Empdes" : "ERP DEVELOPER"
},
{
"__metadata" : {
"id" : "http://XXX:8000/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011240')",
"uri" : "http://XXX:8000/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011240')",
"type" : "ZMM_EMP_SRV.Employee"
},
"Empid" : "00011222",
"Empname" : "Aldrin",
"Empadd" : "IIS, RAKAH",
"Empdes" : "UI5 DEVELOPER"
},
{
"__metadata" : {
"id" : "http://XXX:8000/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011930')",
"uri" : "http://XXX:8000/sap/opu/odata/SAP/ZMM_EMP_SRV/EmployeeSet('00011930')",
"type" : "ZMM_EMP_SRV.Employee"
},
"Empid" : "00011930",
"Empname" : "Barry Alpha",
"Empadd" : "New Jersey",
"Empdes" : "ABAP ANALYST"
}
]
}
}
Could you please guide me how should I code for the right path?
Regards,
Firoz.
Hi Firoz,
What i guess is the model is not getting populated when your statement is executed as it is an asynchronous call.
Hope this should work for you, and try writing it in onAfterRenderingFunction() rather than init().
If it still does'nt work, you can have a fresh post and get help.
Thanks,
Ashwin
Hi Ashwin,
Thanks it's working now.
The statement ("/results/0") will work fine and we will get the value in variable empname.
var results = oJsonModel.getProperty("/results/0");
var empname = results.Empname;
The statement ("/results/0") will NOT work. So, we have to change the code to
var empname = oData.Empname;
to get the value in empname
Many Thanks,
Firoz.
Hi Ashwin,
Go through the below links
Consume NetWeaver Gateway services via SAPUI5 - Part 1
Regards,
Venu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Ashwin,
Please check the below link this should help
http://scn.sap.com/docs/DOC-47626
Regards
Sri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
H Ashwin ,
You can directly attach parameter in the POST call URL that you make for the service.
See example in the given link. We are doing same in our project.
rest - Firefox Add-on RESTclient - How to input POST parameters? - Stack Overflow
Hi Ashwin,
Below is the sample code that we use for Batch operation for status change where we pass parameters in the service URL.
You have to implement the same service in the gateway system to accept the passed service.
You can consult with your SAP gateway service developer for further development.
var serviceObjUrl = "serverURL"; | ||
var action = new sap.ui.model.odata.ODataModel(serviceObjUrl, true); | ||
action.setTokenHandlingEnabled(true); | ||
action.setHeaders({"Content-Type" : "multipart/mixed"}); | ||
action.setUseBatch(true); | ||
for(var count=0;count<a.length;count++){ | ||||
var perNo = a[count]; | ||||
action.addBatchChangeOperations([ | ||||
action.createBatchOperation("ChangeStatus?NewStatus='2'&NewSubstatus='B'&OldStatus='2'&OldSubstatus='A'&PersonnelNumber='"+ perNo+ "'", "POST") ]); | ||||
} | ||||
action.submitBatch(function(oData, response) { | ||||
console.log(oData); |
}
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.