Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
514 views
in Technique[技术] by (71.8m points)

javascript - Netsuite : How to show the render pdf in browser directly but not download?

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Have you tried to set the inline parameter as true?

response.writeFile(newfile, true);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...