Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Q: Getting a value from a very simple web-service

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.

Tags:
replied
  1. oModel.read("/guidSet('X')?", {
  2. success : function(oData, response) { 
  3. var oJsonModel = new sap.ui.model.json.JSONModel(); 
  4. oJsonModel.setData(oData.results); 
  5.              
  6. sap.ui.getCore().setModel(oJsonModel); 
  7. var formId = sap.ui.getCore().getModel().getProperty("/Formid"); 
  8. alert(formId); //SOMEWHY IS NULL 
  9.         }

  10. }); 
0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question