Download button in suitelet page to downlad a file

To download a file in the submit type button click from a suitelet page, first save the file into the file cabinet, then write below given code in suitelet page button action function.

// to create the file in file cabinet
let fileCreated = file.create({
                  name: "Order_Item_with_box_quantity.csv",
                  fileType: file.Type.CSV,
                  contents: csvContent,
                  folder: "3834524",
                  encoding: file.Encoding.UTF_8,
                  isOnline: true
                 });

// to save the file 
let savedFile = fileCreated.save();

//to download the file
scriptContext.response.writeFile({
              file: fileCreated,
              isInline: true
            });

Leave a comment

Your email address will not be published. Required fields are marked *