簡體   English   中英

在SuiteScript 2.0中生成文件后如何重定向

[英]How to Redirect after Generating File in SuiteScript 2.0

我的目標是在生成文件后重定向頁面,但是下面的代碼不會生成文件,因為它會重定向到另一個頁面。 重定向后如何生成文件? 服務器端腳本(Suitelet)中是否可以做到這一點?

Suitelet SuiteScript 2.0:

response.writeFile({
              file:loanPortFolio
            });

//There are no redirect before, only generate file, but because i can't generate again , 
//I need to refresh the page to generate again. so i Add this line of code to redirect me to same page.

 response.sendRedirect({
          type: http.RedirectType.SUITELET,
          identifier : 'customscript_loan_port_detailed_report',
          id : 'customdeploy_loan_portf_detailed_report',
          parameters: {
                    type : 'monthly'
                  }
 });

//Result? I can't generate because it redirect to another page -_-

簡單的答案:不能同時擁有writefile和redirect:如果一個被執行,則另一個將被“取消”。

您沒有輸入完整的代碼,但是我假設您在Suitelet中使用表單,並且確實為表單添加了一個提交按鈕,並且在POST中您正在生成文件並使用writeFile。

如果是這種情況,那么一種實現目標的方法是在生成文件后,而不是使用writeFile,而是可以在表單中添加HTML字段並將其值設置為以下形式:

'<a href=[url] target=_blank>Download file</a>'

使用:[url]是您可以從文件對象(loanPortFolio)獲得的鏈接。

這樣,提交后,用戶將看到鏈接,並且由於目標是'_blank',因此將在新的選項卡/窗口中生成文件,因此表單窗口將保持打開狀態,並且可以再次使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM