cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to read value from odata

lalitha_p2
Explorer
0 Kudos

Hi All,

I am not able to read value from odata,

but i can see an json alert..

I tried this way,,,oData.Type   and oData.results[0].Type

Console throws an error " Type Property not found"

Regards,

Lalitha

Accepted Solutions (0)

Answers (4)

Answers (4)

sivakumar_mobility
Active Participant
0 Kudos

Hi Lalitha,

Did you include library to your code in order to read Odata from sap gateway?

With Regards,

Siva

lalitha_p2
Explorer
0 Kudos

Please find the code below::

var postdata1 = {

  Reason : d1,

  StartDate:dateformat,

      StartTime:time1,

  EndDate:dateformatend,

  EndTime:time2,

  Destination:d6,

  AdvanceAmount:d7,

  CostCenter:"",

  EmpNum:empnum,

  Country:"",

  Currency:"",

  Remark:"",

        

  CreateTripI:[{

         Receiptno:"",

         ExpType: d10,

         RecAmount: d12,

         RecCurr: d13,

         RecDate: d11format,

         Shorttext: ""

  },

var url3 ="/sap/opu/odata/sap/ZHCP_EXPENSE_REPORT_SRV/CreateTripHSet";

  var oModel3 = new sap.ui.model.odata.ODataModel(url3, false,usr,pwd);

  oModel3.refreshSecurityToken();

  oModel3.setHeaders({

  "X-Requested-With": "XMLHttpRequest",

          "Content-Type": "application/atom+xml",

          "DataServiceVersion": "2.0",      

          "X-CSRF-Token":"Fetch"         

  });

  var token3="";

  oModel3.read('',null,null,true,function(oData, oResponse) { 

   token3 = oResponse.headers['x-csrf-token']; 

   });

    oModel3.setHeaders({ 

   "X-Requested-With": "XMLHttpRequest",                        

                   "Content-Type": "application/atom+xml", 

                   "DataServiceVersion": "2.0",  

                   "Accept": "application/atom+xml,application/atomsvc+xml,application/xml", 

                   "X-CSRF-Token": token3

                  

                   }); 

  

    

oModel3.create('', postdata1, null, function(oData, oResponse){

   

    alert(JSON.stringify(oData));

    var typew = oData.Message;

   

    alert(typew);

Abdul_Waheed
Contributor
0 Kudos

Share oData and oResponse values

naveenraj_a
Active Participant
0 Kudos

Hi Lalitha,

Try handling the Headers and CSRF token using ODataModel, so that you don't want to set the Headers Explicitly.

ODataModel class will handle those internally. Check the API link below for possible parameters to be passed.


SAPUI5 SDK - Demo Kit

Check the below code for creating a OData model and calling create with payload.

var sURL = "/sap/opu/odata/sap/ZHCP_EXPENSE_REPORT_SRV/";

var oModel = new sap.ui.model.odata.ODataModel(sURL);

oModel.create("/CreateTripHSet", postdata1, null,

        function(oResponse)

        {

            alert(oResponse.Message);

        },

    function(error)

    {

            alert("Error");

    });

Check this link for Create method in OData.

SAPUI5 SDK - Demo Kit

Regards

Naveenraj

lalitha_p2
Explorer
0 Kudos

Hi,

  •    <link href="CreateTripHSet('00003012')/CreateTripI" rel="self" title="CreateTripISet"/>
  •    <entry>
  •    <id>/sap/opu/odata/sap/ZHCP_EXPENSE_REPORT_SRV/CreateTripISet(EmpNo='00000000',Receiptno='',TripNo='0000000000')</id>
  •    <title type="text">CreateTripISet(EmpNo='00000000',Receiptno='',TripNo='0000000000')</title>
  •    <updated>2016-01-05T07:44:26Z</updated>
  •    <category term="ZHCP_EXPENSE_REPORT_SRV.CreateTripI" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
  •    <link href="CreateTripISet(EmpNo='00000000',Receiptno='',TripNo='0000000000')" rel="self" title="CreateTripI"/>
  •    <content type="application/xml">
  •    <m:properties>
  •    <d:EmpNo>00000000</d:EmpNo>
  •    <d:Receiptno/>
  •    <d:Type>E</d:Type>
  •    <d:Message>Travel expense type AIRP is not stored in Customizing</d:Message>
  •    <d:TripNo>0000000000</d:TripNo>
  •    <d:ExpType/>
  •    <d:RecAmount/>
  •    <d:RecCurr/>
  •    <d:RecDate m:null="true"/>
  •    <d:Shorttext/>
  •    </m:properties>
  •    </content>
  •    </entry>
  •    </feed>
  •    </m:inline>
  •   </link>
Abdul_Waheed
Contributor
0 Kudos

do

console.log(oData+" "+oResponse);

in your create method & share what oData and oRespone has

lalitha_p2
Explorer
0 Kudos
Abdul_Waheed
Contributor
0 Kudos

what does oResponse has?

lalitha_p2
Explorer
0 Kudos

is that screen shot not clear??

I tried console.log,(),i am getting[object object] [object object]

Former Member
0 Kudos

Hi,

can you please share your code?

Regards,

Kuldeep

Abdul_Waheed
Contributor
0 Kudos

The way you are referring to JSON structure might be wrong.

Can you share your OData resonse.