Task: General
We can add custom data in advanced PDF templates using the render function. When rendering PDFs using suitelet we can load the Advanced PDF template and inject custom add that should be added to the template. For that, we need to prepare the custom data in an object or JSON format. After that, we can add them using AddcustomDataSource built-in function. Instead of replacing the data in XML template the best practice is use this method in order to render the data using render module.
var categoryObj = {};
myFile.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "items",
data: {
items: items,
category: items.reduce(function(i, j) {
if (!categoryObj[j.productCategory]) {
categoryObj[j.productCategory] = true;
i.push(j.productCategory)
}
return i;
}, [])
}
});