NetSuite - Writing A File To Suitelet Response To Directly Download File
Hope you can help. Something which appears so small is bugging the heck out of me!!
All I want to do in SuiteScript 2.0 is directly download a CSV file to the client as soon as I hit the SUBMIT button on a Suitelet. My code downloads to the client, but the content in the file is incorrect.
The following code creates the file (successfully):
//creating CSV file
var fileObj = FILEMODULE.create({
name: 'ThreePLreport.csv',
fileType: FILEMODULE.Type.CSV,
contents: contents
});
The last snippet of code writes the file to the client side:
context.response.writeFile(fileObj,true);
Now - when I come to open the file, it looks like this:
When I save the same file on the filing cabinet, it looks correct:
I have tried adding HEADERS to the code, like:
context.response.addHeader({
name: 'Content-Type:',
value: 'text/csv' //text/csv
});
context.response.addHeader({
name: 'Content-Disposition',
value: 'attachment; filename="report1.csv"'
});
This doesn't seem to help in correcting the content inside the CSV file. Still displays the HTML code as you saw above.
Any ideas?
Thanks in advance!
Answer
I've done almost exactly this many times. It looks like you are not returning after you write the file. e.g.:
context.response.writeFile({
file:fileObj,
isInline:false
});
return;
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM