cancel
Showing results for 
Search instead for 
Did you mean: 

PDF download in SAPUI5 using oData

fahad_saplearning
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (6)

Answers (6)

former_member516423
Participant

Hi SAP Learner,

You can try this approach

File Upload/Download through NetWeaver Gateway

Regards,

Tri

fahad_saplearning
Participant
0 Kudos

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

Former Member
0 Kudos

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


jr_golive
Explorer
0 Kudos

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?

fahad_saplearning
Participant
0 Kudos

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

fahad_saplearning
Participant
0 Kudos

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

former_member185414
Active Contributor
0 Kudos

Couple of things you can update here after verifying your codebase -

1. See sample code here

2. Debug the behavior of GET_STREAM or READ_STREAM method.

fahad_saplearning
Participant
0 Kudos

Hello Ankit,

The link mentioned talks about upload. In fact, I am looking for an example where download happens through an oData service with date input within entityset parameter.

Would be of great help if you can give an example which meets the above specs.

Regards,

SAP Learner

former_member186852
Contributor
0 Kudos

Could you please share the Network response of the browser.

Regards,

Meghal Shah

desiree_matas
Contributor
0 Kudos

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

fahad_saplearning
Participant
0 Kudos

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

fahad_saplearning
Participant
0 Kudos

Can someone please help me here?