Is there a way to have a selection of many transactions printed into a single PDF document? I only see two options which seem to have significant drawbacks:
1) Load individual records into each of their own nlobjTemplateRenderer objects, and then stitch them all together within tags before rendering to PDF. Has a limit of less than 50 transactions depending on other actions taken when used within a Suitelet.
2) Do a search based upon internals IDs of selected records and pass the search results into a nlobjTemplateRenderer object. This method, based upon existing documentation, does not lead me to believe that it will properly display records with line data as result columns completely within a single document.
It almost seems like my best option is #1, but to split the desired transaction up into groups of 5-10 records and repeatedly calling a Suitelet with the small groups in the hopes of meeting the 45-second timeout limit of nlapiRequestURL before stitching together all of the results and returning the final PDF document. I pretty much see a basic form of that as the following:
// initial called function that will return completed PDF document file
function buildPdfFromRecords() {
var pdfBuilder = [];
var selectedIDs = [];
var chunks = chunkify(selectedIDs, 10);
for (var c = 0; c < chunks.length; c++) {
var param = { id_list : JSON.stringify(chunks[s]) };
var result = nlapiRequestURL(url, param).getBody();
pdfBuilder.push(result);
}
var finalXML = "<pdfset>" + pdfBuilder.join("") + "</pdfset>";
var pdfDoc = nlapiXMLToPDF(finalXML);
}
// function in suitelet called by url to handle individual groups of record internal IDs
// to mitigate scripting governance limits
function handleRecordIdListRequest(request, reponse) {
var idList = JSON.parse(request.getParameter("id_list"));
var templateXML = nlapiLoadRecord("template.txt").getValue();
var pdfBuilder = [];
for (var i = 0; i < idList.length; i++) {
var transRecord = nlapiLoadRecord("recordtype", idList[i]);
var renderer = nlapiCreateTemplateRenderer();
renderer.setTemplate(templateXML);
renderer.addRecord("record", transRecord);
pdfBuilder.push(renderer.renderToString());
}
response.write(pdfBuilder.join(""));
}
If this is really the best way, then so be it, but I'm hoping there's a more elegant solution out there that I'm just not seeing.