Freemarker provides ability to get values from any record and pass them to a custom Template. It operates with fields' ids (can be found in Record Browser) and has its' own Freemarker syntax.
Advanced Printing feature uses Freemarker syntax and can be used as an example of how the code looks like.
An example can be found under Customization > Forms > Advanced PDF Templates > Customize for instance Standard Invoice PDF/HTML Template > Source code
Suitelet example with Freemarker syntax
var salesOrderID = 1002;
var record = nlapiLoadRecord('salesorder', salesOrderID);
var renderer = nlapiCreateTemplateRenderer();
var item;
var template = '<?xml version="1.0"?><html><head><meta charset="utf-8"></head><body>';
template += '<table>';
template += '<tr><td align="right"><b>SALES ORDER</b></td><td><b>#${record.tranid}</b></td></tr>';
template += '<td align="right"></td></tr><tr><td align="left">${record.trandate}</td></tr>';
template += '</table>';
template += '</br>';
template += '<table>';
template += '<tr><td><b>${record.billaddress@label}</b></td><td><b>${record.total@label?upper_case}</b></td></tr>';
template += '<tr><td>${record.billaddress}</td><td align="right">${record.total}</td></tr>';
template += '</table>';
template += '</br>';
template += '<table>';
template += '<tr><th>${record.otherrefnum@label}</th><th>${record.shipmethod@label}</th></tr>';
template += '<tr><td>${record.otherrefnum}</td><td>${record.shipmethod}</td></tr>';
template += '</table>';
template += '</br>';
template += '<table border="1">';
template += '<#list record.item as item>';
template += '<thead>';
template += '<tr><th align="center">${item.quantity@label}</th><th>${item.item@label}</th><th align="right">${item.rate@label}</th><th align="right">${item.amount@label}</th></tr>';
template += '</thead>';
template += '<tr><td align="center" line-height="150%">${item.quantity}</td><td><span class="itemname">${item.item}</span><br />${item.description}</td><td align="right">${item.rate}</td><td align="right">${item.amount}</td></tr>';
template += '</#list>';
template += '</table>';
template += '<hr />';
template += '<table>';
template += '<tr><td colspan="4"> </td><td align="right"><b>${record.subtotal@label}</b></td><td align="right">${record.subtotal}</td></tr>';
template += '<tr><td colspan="4"> </td><td align="right"><b>${record.taxtotal@label} (${record.taxrate}%)</b></td><td align="right">${record.taxtotal}</td></tr>';
template += '<tr><td background-color="#ffffff" colspan="4"> </td><td align="right"><b>${record.total@label}</b></td><td align="right">${record.total}</td></tr>';
template += '</table>';
template += '</body>';
template += '</html>';
renderer.setTemplate(template);
renderer.addRecord('record', record);
response.setContentType('HTMLDOC');
renderer.renderToResponse(response);
No comments:
Post a Comment