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:如果一个被执行,另一个将是 "cancelled"。
你没有放完整的代码,但我假设你在一个套件中使用表单,你确实为你的表单添加了一个提交按钮,并且在 POST 中你正在生成文件和使用 writeFile.
如果是这样,那么实现您的目标的一种方法是,在 post 中,生成文件后,您可以在表单中添加一个 HTML 字段,而不是使用 writeFile并将其值设置为:
'<a href=[url] target=_blank>Download file</a>'
with: [url] 是 link 你可以从你的文件对象 (loanPortFolio) 中得到。
有了这个,提交后,用户将看到 link,因为目标是 '_blank',文件将以新的 tab/window 形式生成 [=29] =] 将保持打开状态,可以再次使用。
我的目标是在生成文件后重定向页面,但我下面的代码没有生成文件,因为它重定向到另一个页面。重定向后如何生成文件?是否可以在服务器端脚本(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:如果一个被执行,另一个将是 "cancelled"。
你没有放完整的代码,但我假设你在一个套件中使用表单,你确实为你的表单添加了一个提交按钮,并且在 POST 中你正在生成文件和使用 writeFile.
如果是这样,那么实现您的目标的一种方法是,在 post 中,生成文件后,您可以在表单中添加一个 HTML 字段,而不是使用 writeFile并将其值设置为:
'<a href=[url] target=_blank>Download file</a>'
with: [url] 是 link 你可以从你的文件对象 (loanPortFolio) 中得到。
有了这个,提交后,用户将看到 link,因为目标是 '_blank',文件将以新的 tab/window 形式生成 [=29] =] 将保持打开状态,可以再次使用。