on 06-08-2015 8:00 AM
Hey guys,
i am having a slight problem with I hope a very easy question for you. I am trying to read a single value (Formid) from a web-service that has only the read (GetEntity) function to a value in javascript.
The service has a dummy input and an output that is a Globally Unique Identifier (Formid). The service works properly :
But I cant get the value to my javascript variable. Am I trying to get it wrong? The code is as follows :
onInit: function() {
var sServiceUrl = "http://my.uri.domain:port/sap/opu/odata/sap/GENERATE_GUID_SRV_01/";
var oModel = new sap.ui.model.odata.ODataModel(sServiceUrl, true);
var oJsonModel = new sap.ui.model.json.JSONModel();
oModel.read("/guidSet('X')?", null, null, true, function(oData, response) {
oJsonModel.setData(oData);
});
sap.ui.getCore().setModel(oJsonModel);
var formId = sap.ui.getCore().getModel().getProperty("{/Formid}");
alert(formId); //SOMEWHY IS NULL
},
I hope You can help me,
Mario.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
actually what is the purpose of that 'X'??
can't you just do /guidSet ?
Changed it to :
oModel.read("/guidSet('X')", {
success: function(oData, response) {
var oJsonModel = new sap.ui.model.json.JSONModel();
oJsonModel.setData(oData.results);
sap.ui.getCore().setModel(oJsonModel);
var formId = sap.ui.getCore().getModel().getProperty("/Formid");
alert(formId);
}
});
It still says undefined.
Hi Mario,
Do like this and see if it's working.
var oModel = "http://my.uri.domain:port/sap/opu/odata/sap/GENERATE_GUID_SRV_01/";
var sRead = "/guidSet(DUMMYVARIABLENAME='X')" ;
oModel.read( sRead, null, null, true, function(oData, oResponse){
var formId = oData.formId;
},function(){
alert("Read failed");});
or you may also use proxy in your URL.
var oModel = "proxy/http/my.uri.domain:port/sap/opu/odata/sap/GENERATE_GUID_SRV_01/";
See here if you are getting your formId.
Also check if you are getting your data in console.
console.log(oModel);
Regards
Dhananjay
Hey Maksim,
Got it now !!
I changed the oData.results (as I don't have sets) to just oData and got the value!
oModel.read("/guidSet('X')", {
success: function(oData, response) {
var oJsonModel = new sap.ui.model.json.JSONModel();
oJsonModel.setData(oData);
sap.ui.getCore().setModel(oJsonModel);
var formId = sap.ui.getCore().getModel().getProperty("/Formid");
alert(formId);
}
});
Thanks a lot for your help!
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.