I have created a button to render pdf with UserEvent, ClientScript and Suitelet.
1
And now I just successfully created a pdf and download it,
2
but I expected the pdf should be opened with browser automatically but not download.
3
Here is my code.
UserEvent:
function beforeLoad(context) {
context.form.addButton({
id: 'custpage_monthly_report',
label: 'Monthly Report',
functionName: 'clickToMonthlyReport()'
});
context.form.clientScriptModulePath = 'SuiteScripts/PolicySalesOrderScript/PolicySalesOrderStatusUpdate/policySalesOrder_statusUpdate_CS.js';
}
ClientScript :
var suiteletUrl = url.resolveScript({
scriptId: 'customscript_rsomr', // my suitelet script id
deploymentId: 'customdeploy_rsomr', // my suitelet deployment id
returnExternalUrl: false,
params: {custom_id: currentRecord.get().id,},
});
window.open(suiteletUrl);
Suitelet :
const onRequest = (scriptContext) => {
var request = scriptContext.request;
var response = scriptContext.response;
var recordID = scriptContext.request.parameters.custom_id;
var xmlTemplateFile = file.load('Templates/Monthly Report.xml');
var renderer = render.create();
renderer.templateContent = xmlTemplateFile.getContents();
renderer.addRecord('record', record.load({
type: record.Type.SALES_ORDER,
id: recordID
}));
var customrecord1070SearchObj = search.create({
type: "customrecord1070",
filters:
[
["custrecord_iv_policy_num", "anyof", recordID]
],
columns:
[
search.createColumn({
name: "scriptid",
sort: search.Sort.ASC,
label: "Script ID"
}),
search.createColumn({name: "custrecord_iv_policy_num", label: "Policy Number"}),
search.createColumn({name: "custrecord_iv_report_date", label: "Report Date"}),
search.createColumn({name: "custrecord_iv_tour_from", label: "From"}),
search.createColumn({name: "custrecord_iv_tour_to", label: "To"}),
search.createColumn({name: "custrecord_iv_tour_start", label: "Start Date"}),
search.createColumn({name: "custrecord_iv_tour_fin", label: "Finished Date"}),
search.createColumn({name: "custrecord_iv_num_of_day", label: "NO. OF DAY"}),
search.createColumn({name: "custrecord_iv_tour_sum", label: "Sum Insured"}),
search.createColumn({name: "custrecord_iv_tour_premium", label: "Premium"})
]
});
var searchResultCount = customrecord1070SearchObj.runPaged().count;
log.debug("customrecord1070SearchObj result count", searchResultCount);
var results = customrecord1070SearchObj.run().getRange(0,1000);
renderer.addSearchResults({
templateName: 'results',
searchResult: results
});
var newfile = renderer.renderAsPdf();
response.writeFile(newfile, false);
}
question from:
https://stackoverflow.com/questions/65895284/netsuite-how-to-show-the-render-pdf-in-browser-directly-but-not-download