Skip to Content

PDF download in SAPUI5 using oData

Hello,

I want to invoke an oData read service which returns PDF file as output. The oData url would look as follows:

/sap/opu/odata/SAP/ZYG_PDF_DWNLD_SRV/FILE_ENTITYSet('XYZ')/$value

I know how to invoke read operation from an entity set using standard SAPUI5 APIs. However, I am confused about the $value suffix in this oData invocation. How can I invoke the above url using SAPUI5 oData APIs.

Please provide the SAPUI5 code snippet which executes the above oData service

Note: If nothing is possible, my final work around is: construct the url in the above format using javascript and execute it using an ajax call. Before I do that, I would like to know the approach using standard API, hence posted this thread.

SAP Learner

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • Apr 18, 2018 at 04:49 AM

    Hi SAP Learner,

    You can try this approach

    File Upload/Download through NetWeaver Gateway

    Regards,

    Tri

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Tri,

      Thanks for that.

      The topic in the link talks more about the oData development for File upload/download. I am looking for SAPUI5 code snippet which can invoke the oData file download service in a standard approach. Can you please provide that information

      Regards,

      SAP Learner

  • Oct 28, 2018 at 06:30 AM
    -1

    Hey,

    You can visit the below article for pdf download in sapui using odata. Hope so this will help you out.


    blogs.sap.com/2016/11/23/pdf-download-option-with-sapui5/


    Regards,

    Adrian Gates

    System Admin - CloudDesktopOnline


    Add comment
    10|10000 characters needed characters exceeded

  • Apr 17, 2018 at 09:44 AM

    Can someone please help me here?

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 17, 2018 at 10:53 AM

    Hi SAP learner,

    This is more related to the gateway technology than to UI5. Adjust your tags so that the community can address the question better.

    Best regards,

    Désirée

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Desiree,

      I have added Gateway service tag also to this thread.

      As my query is to provide the SAPUI5 code snippet for executing the specified oData service, I have retained the primary tag as SAPUI5. I hope you agree with that

      Regards,

      SAP Learner

  • Jun 13, 2018 at 01:47 PM

    Hello All,

    I am trying to execute the following oData url from UI5 controler. It returns pdf file, when executed from Gateway client.

    /sap/opu/odata/XXX/YYY_SRV/PDF_ENTITYSet(Empid='50160458',Begda=datetime'2018-05-31T00:00:00',Endda=datetime'2018-05-31T00:00:00')/$value

    Code which I have tried to execute from controller is as follows:

    var sServicePath = "/PDF_ENTITYSet(Empid='50160458',Begda=datetime'2018-05-31T00:00:00',Endda=datetime'2018-05-31T00:00:00')/$value";

    oBackendModel.read(sServicePath, null, null, true, that.function(){ alert("Read success"),function(){ alert("Read failed");});

    However, it fails always and shows "Read Failed" alert. I have gone through many examples where input is a normal string everywhere and tried to follow that approach here as well. I did not see single example where date is used as input to Entity set parameter. I am guessing that the issue is with datetime input in the url supplied during read.


    Can anyone spot the issue here and provide suggestion on how to make this working?


    Regards,

    SAP Learner

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 25, 2018 at 05:10 PM

    I know is a pretty old post. But I'm facing the same problem related to the oData PDF request. I just keep getting the "no handler for data" error message, when I make the $value call. I'm using the "oModel.read(sRead" call structure, and some others, but nothing seems to work.

    Any change you or any other can help me?

    Add comment
    10|10000 characters needed characters exceeded

    • Hey Jose..

      I could not get a solution here. At the end, I have made an Ajax call using XMLHttpRequest call (not oData read. To my surprise, jQUery AJAX call also did not work as expected for me!!), which gave me the result.. Not sure why oData.read/jQuery AJAX did not yield the result!! :(

      I mean, solution is something like this:

      var xhr = new XMLHttpRequest();

      xhr.open('GET', "/sap/opu/odata/PDF_ENTITYSet(Empid='50160458',Begda=datetime'2018-05-31T00:00:00',Endda=datetime'2018-05-31T00:00:00')/$value" , true);

      xhr.responseType = 'blob'; xhr.onload = function (e) { var oPdf_Blob = xhr.response; //That can be saved to db

      }

      oPdf_Blob has the PDF object.

      Regards,

      SAP Learner