RE: I am trying to Render search result onpdf via Suitescript 2.0 render.addSearchResults function, however, on pdf searchResults are not rendered

Can anyone advice where I am making mistake, the pdf is rendered correctly but search Reults are not rendered on pdf

/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
// This sample shows how to render search results into a PDF file.
define([‘N/render’, ‘N/search’,’N/file’], function(render, search,file) {
function onRequest(options) {
var request = options.request;
var response = options.response;

var xmlTemplateFile = file.load(‘Templates/PDF Templates/custtmpl_121_t2418832_522.template.xml’);

var rs = search.create({
type: “customer”,
filters:
[
[“balance”,”notequalto”,”0.00″],
“AND”,
[“internalid”,”anyof”,”126″],
“AND”,
[“transaction.trandate”,”within”,”2022/07/01″,”2023/01/31″],
“AND”,
[“transaction.type”,”anyof”,”CustCred”,”CustInvc”,”CustPymt”]
],
columns:
[
search.createColumn({
name: “trandate”,
join: “transaction”,
sort: search.Sort.ASC,
label: “Date”
}),
search.createColumn({
name: “tranid”,
join: “transaction”,
sort: search.Sort.ASC,
label: “Document Number”
}),
search.createColumn({name: “altname”, label: “Name”}),
search.createColumn({
name: “amount”,
join: “transaction”,
label: “Amount”
}),
search.createColumn({
name: “item”,
join: “transaction”,
label: “Item”
}),
search.createColumn({name: “consolbalance”, label: “Consolidated Balance”}),
search.createColumn({name: “balance”, label: “Balance”}),
search.createColumn({
name: “line”,
join: “transaction”,
sort: search.Sort.ASC,
label: “Line ID”
}),
search.createColumn({
name: “type”,
join: “transaction”,
label: “Type”
}),
search.createColumn({
name: “amountremaining”,
join: “transaction”,
label: “Amount Remaining”
}),
search.createColumn({
name: “fxbalance”,
join: “customerCurrencyBalance”,
label: “Balance (Foreign Currency)”
})
]
}).run();

var results = rs.getRange(0, 1000);

log.debug({
title:’Result’,
details:results
})
var renderer = render.create();
log.debug({
title:’renderer’,
details:JSON.stringify(renderer.TemplateRenderer)
})

renderer.templateContent = xmlTemplateFile.getContents();
renderer.addSearchResults({
templateName: ‘custtmpl_121_t2418832_522’,
searchResult: results
});

var newfile = renderer.renderAsPdf();
response.writeFile({file:newfile, isInline:true});
}

return {
onRequest: onRequest
};
});

princeaugustine30 Rookie Asked on February 3, 2023 in SuiteScript.
Add Comment
1 Answers

Hi,

This section is wrong:

renderer.templateContent = xmlTemplateFile.getContents();
renderer.addSearchResults({
templateName: ‘custtmpl_121_t2418832_522’,
searchResult: results
});

templateName would usually be something like mySearchResults.

Then in the template itself, you refer to the results like so:

<#list mySearchResults as result>

Thanks,

Chris

Intermediate Answered on February 6, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.