context.response.writePage
-> While we are creating the form and you want to display a UI page using the SuiteLet
-> Used with the N/ui/serverWidget module to create forms, lists, or sublist
Syntax:
let form = serverWidget.createForm({
title: ‘My Sample Form’
});
form.addField({
id: ‘custpage_textfield’,
type: serverWidget.FieldType.TEXT,
label: ‘Enter Some Text’
});
form.addSubmitButton({
label: ‘Submit’
});
scriptContext.response.writePage(form); // This renders the UI form
};
context.response.writeFile
-> When you want to send a response as PDF, CSV, EXCEL file etc… this method is used.
-> Used with the N/file or N/render module generate the file.
Syntax:
let recordId = scriptContext.request.parameters.recordId;
let renderer = render.create();
renderer.addRecord({
templateName: ‘record’,
record: record.load({
type: record.Type.SALES_ORDER,
id: recordId
}),
});
renderer.setTemplateById(100);
let pdfFile = renderer.renderAsPdf();
scriptContext.response.writeFile(pdfFile, true); // Sends the PDF as inline (view in browser)
(or)
scriptContext.response.writeFile(pdfFile,false); //Download the PDF file in browser.
};