NetSuite : How to Call a Suitelet from MapReduce
How to Call a Suitelet from MapReduce
There are situations when we have to call a suitelet from Mapreduce possibly to trigger it and get a response from it.
There was a scenario for customer where I had to call a PDF suitelet in order to read the contents of PDF and send it customer as batch job. So I used below API to do the work.
Code in Suitelet
Suitelet is doing the job of saving the PDF in filecabinet
var fileObj = file.create({
name: 'invoice_' + invoiceId + '.pdf',
fileType: file.Type.PDF,
contents: pdfFile.getContents(),
folder: folderId
});
var fileId = fileObj.save();
context.response.setHeader({
name: 'Content-Type',
value: 'application/pdf'
});
context.response.setHeader({
name: 'Content-Disposition',
value: 'inline; filename="invoice_' + invoiceId + '.pdf"'
});
context.response.write(pdfFile.getContents());Code in Mapreduce
Mapreduce is doing the job of calling suitelet, reading the content of file from filecabinet and then deleting it.
https.requestSuitelet({
scriptId: "idofsuiteletscript",
deploymentId: "deployidofsuiteletscript",
external: true,
urlParams: {
recId: idofinvoicerecord
}
});
scriptId: "idofsuiteletscript",
deploymentId: "deployidofsuiteletscript",
external: true,
urlParams: {
recId: idofinvoicerecord
}
});