Not able to download Suitelet through suitescript 1.0

I have created a button to export the form data to simple Excel. Everything is working file, even if i try to save this excel file in the file cabinet it gets saved correctly. But when i try to downlaod the excel file, shows wierd single column excel data on the page or system gives either an error or saves an empty excel file. Can anyone help me in how to download the excel file from button click. I think i have issue in my responce.

// this dowloads empty excel
response.setContentType(‘EXCEL’, ‘aaa.xls’, ‘inline’);
response.writePage(xlsFile);

                
Rookie Asked on March 6, 2022 in SuiteScript.
Add Comment
1 Answer(s)

Did you try with response.writeFile instead?

Rookie Answered on March 7, 2022.

Yes, I tried that too, it previews the whole data on HTML page.

on March 7, 2022.

Are you actually creating the file using the file module?  Something like this worked for me in the past:

var encoded = encode.convert({
    string: xmlStr,
    inputEncoding: encode.Encoding.UTF_8,
    outputEncoding: encode.Encoding.BASE_64
});

var strFileName = 'INV' + strInvName + '_' + dateFormat() + '.xls';

var fileObj = file.create({
    name: strFileName,
    fileType: file.Type.EXCEL,
    contents: encoded
});
objResponse.writeFile({
    file: fileObj,
    isInline: false
);
 
on March 8, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor