{
"Field1": "hvl1",
"Field2": "hvl2",
"Field3": "hvl3",
"ItemSet": [
{
"IFLD1": "rv11",
"IFLD2": "rv12",
"IFLD3": "rv13"
},
{
"IFLD1": "rv21",
"IFLD2": "rv22",
"IFLD3": "rv23"
}
],
"NAVRESULT": [
{
"MSG1": "",
"MSG2": ""
}
]
}
pressBtn_oDataCreate: function() {
//Wait-Processing Dialog
var lv_BusyDialog = new sap.m.BusyDialog({
text: "Processing..."
});
//Begin of oDataService's Request Preparation------------------
var lv_srvRequest = {}; //To contain input
lv_srvRequest.ItemSet = []; //Array to accept item level
lv_srvRequest.NAVRESULT = []; //Array to store Result
//Header Input
lv_srvRequest.Field1 = "hvl1";
lv_srvRequest.Field2 = "hvl2";
lv_srvRequest.Field3 = "hvl3";
//Item level input- [Row-1]
var lv_Item = {};
lv_Item.IFLD1 = "rv11";
lv_Item.IFLD2 = "rv12";
lv_Item.IFLD3 = "rv13";
lv_srvRequest.ItemSet[0] = lv_Item; //append to zero'th positon of array
//Item level input- [Row-2]
var lv_Item = {};
lv_Item.IFLD1 = "rv21";
lv_Item.IFLD2 = "rv22";
lv_Item.IFLD3 = "rv23";
lv_srvRequest.ItemSet[1] = lv_Item; //append to 1st postion of array
//Blank 'Result' structure
var lv_res = {};
lv_res.MSG1 = "";
lv_res.MSG2 = "";
lv_srvRequest.NAVRESULT[0] = lv_res; //append to 1st postion of array
//End of oDataService's Request Preparation--------------------
//Odata Service URL Access: when running app from Eclipse
var lv_oDataUrl = "proxy/http/hostAddr:8000//sap/opu/odata/sap/ZTEST_ODATA_SRV/";
var lv_OModel = new sap.ui.model.odata.ODataModel(lv_oDataUrl, true, "userid", "password");
sap.ui.getCore().setModel(lv_OModel);
/*
//Odata Service URL Access: when running app from Fiori Launchpad
var lv_oDataUrl = "/sap/opu/odata/sap/zmpq_sto_po_srv_srv/";
var lv_OModel = new sap.ui.model.odata.ODataModel(lv_oDataUrl, true);
sap.ui.getCore().setModel(lv_OModel);
*/
//Open Busy Dialog when request processing
lv_OModel.attachRequestSent(function(){
lv_BusyDialog.open();
});
// Calling Odata Service using OModel.create
lv_OModel.setHeaders({
"X-Requested-With" : "XMLHttpRequest",
"Content-Type" : "application/json",
"DataServiceVersion" : "2.0",
"Accept" : "application/atom+xml,application/atomsvc+xml,application/xml",
"X-CSRF-Token" : ""
});
//Call the create request
lv_OModel.create('/HeaderSet', lv_srvRequest, null, function(oData, oResponse) {
lv_BusyDialog.close(); //Close Busy dialog
//extract the result
var lv_result = oResponse.data;
var msg1 = lv_result.NAVRESULT.results[0].MSG1;
var msg2 = lv_result.NAVRESULT.results[0].MSG2;
var lv_msg = msg1 + " " + msg2;
//To display result in pop-up
sap.m.MessageBox.show( lv_msg, {
icon : sap.m.MessageBox.Icon.SUCCESS,
title : "oData Response",
onClose: function(oAction) {
//do somthing if required
}});
}, function(err) {
lv_BusyDialog.close(); //Close Busy dialog
var lvErrTxt = err.message;
sap.m.MessageBox.show( "OData Response: " + lvErrTxt, {
icon : sap.m.MessageBox.Icon.ERROR,
title : "Do you want to try again ?",
actions: [sap.m.MessageBox.Action.YES, sap.m.MessageBox.Action.NO],
onClose: function(oAction) {
if ( oAction === sap.m.MessageBox.Action.YES ) {
//If Yes clicked, one more chance to try again
}
if ( oAction === sap.m.MessageBox.Action.NO ) {
//If No clicked, then Cancel
}
}}); //MessageBox close
}); //End of OData Service Call
},
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
8 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |