Skip to Content
0

Unable to download Document using xsjs

Apr 04, 2017 at 10:14 AM

171

avatar image

Hi All,

I am trying to implement the functionality of downloading file (Word Document ) from Hana DB Table.

I stored a file in HANA DB and trying to download the file through UI.

But when i try to run the xsjs service am able to download the file successfully.

But when am trying to call the same xsjs on click it is throwing the below error.

The following problem occurred: parsererror - Word.doc,200,OK

Below is my code return to call xsjs service

downloadDocument : function()

{

var downloadModel = new sap.ui.model.json.JSONModel();

var caseParameters = {}; var caseId = sap.ui.getCore().byId("casesViewId").getValue(); caseParameters.CASEID = caseId;

downloadModel.loadData('http://xx.xxx.xxx.xx:xxxx/Valuefact/services/dowload.xsjs',caseParameters);

}

Could anybody please help me to resolve the issue.

Regards,

Shekar

scncopy.txt

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Mantri Shekar Apr 04, 2017 at 11:10 AM
0

Hi Florian Pfeffer,

Every assumption made by you is perfectly right.

As per you suggestion i cahnged the code as below.

downloadDocument : function()

{

var downloadModel = new sap.ui.model.json.JSONModel();

var caseParameters = {};

var caseId = sap.ui.getCore().byId("casesViewId").getValue(); caseParameters.CASEID = caseId;

//downloadModel.loadData('http://xx.xxx.xxx.xx:xxxx/Valuefact/services/dowload.xsjs',caseParameters,'POST'); window.open('http://xx.xxx.xxx.xx:xxx/Valuefact/services/dowload.xsjs',caseParameters);

}

This time after triggering the aboce method in a new window it is giving a message as "Document not found"

Could you please help me how can i resolve it.

Regards,

Shekar.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Have you checked the information you get in the developer console of your browser (http status, any errors, ...)?
Have you checked that your service path is correct (is the typo in "dowload.xsjs" - instead of "download.xsjs" - correct)?
The 2nd argument for window.open is not an object which can be used for parameters like your caseid, you have to add the parameter to the URL.

0

Florian,

I Checked after doinf some research i came to know that in json model am passing object but in window.open method we cant pass like that.

Here we need to pass that variable inside the xsjs service.

Now am able to do it.

Thanks for your suggestions

0
Florian Pfeffer
Apr 04, 2017 at 11:02 AM
0

Let me assume what you are trying to do: You read your word document via from a DB table and wanna download it via a browser window (according to your content-disposition response header setting set to an attachment value). When you are executing the service directly in the browser it works (cause the response is directly processed by the browser), if you try to do it in your UI5 app with the shown coding it does not work. Right?

If it is so, the coding does not work, cause you are trying to load the word document via a JSON Model. The loadData method tries to parse the response, cause a a JSON Model expects to get a JSON encoded response. That is not the case in your situation, cause your xsjs service does not deliver a JSON encoded response.

If you wanna download just the file, for instance just use the window.open function to call your xsjs service. This function calls your service and the browsers downloads your attachment.

Please also adjust the response content-type header in your xsjs service from "text/plain" to the valid value for your word format.

Regards,
Florian

Share
10 |10000 characters needed characters left characters exceeded