We are having a freemaker XML PDF issue where when...
# suitescript
s
We are having a freemaker XML PDF issue where when we print via Advanced HTML the items are sorted, but not via custom sutelet
👀 1
Copy code
<#list record.item?sort_by("displayname") as item>
            <#if item_index == 0>
                <thead>
                    <tr>
                        <th colspan="2" align="center">#</th>
                        <th colspan="12">${item.item@label}</th>
                        <th colspan="3" align="center">${item.quantity@label}</th>
                        <th colspan="3">${item.units@label}</th>
                        <th colspan="4" align="right">${item.rate@label}</th>
                        <th colspan="6" align="right">Qty received</th>
                    </tr>
                </thead>
            </#if>
            <tr>
                <td colspan="2" align="center">${item_index + 1}</td>
                <td colspan="12">
                   <span class="itemname">${item.item?split(" ")[0]!""} </span><br />${item.description!""} <br/> ${item.vendorname!""}
                </td>
                <td colspan="3" align="center">${item.quantity}</td>
                <td colspan="3">${item.units}</td>
                <td colspan="4" align="right">${item.rate}</td>
                <td colspan="6" align="right"></td>
            </tr>
        </#list>
u
do you have the SL code ?
s
Copy code
function onRequest(options) {
    var request = options.request;
    var response = options.response;
    var type = request.parameters.type;
    var id = request.parameters.id;
    if (!type || !id) {
      var errorHtml = file.load({ id: "/SuiteScripts/UI/html/400.html" });
      response.setHeader({ name: "Content-Type", value: "text/html" });
      response.write(errorHtml.getContents());
      return;
    }
    var templateObject = chooseTemplate(type);
    let printobj = { type, id, templateObject };
    var xmlTmplFile = file.load({ id: templateObject.pdf });
    var myFile = render.create();
    myFile.templateContent = xmlTmplFile.getContents();

    myFile.addRecord({
      templateName: "record",
      record: record.load({
        type: templateObject.recordtype,
        id: id,
      }),
    });
    var invoicePdf = myFile.renderAsPdf();
    response.writeFile(invoicePdf, true);
  }
a
i have worked on custom pdfs. i can make a custom pdf template using suiteql and advanced html ,css.
n
That is a very odd issue, I cannot rationalise in my head why it would be happening. Hopefully someone has an insight in to any difference with how the template is applied in both scenarios and that helps. Certainly not what I would have expected!
b
Im guessing the html version was printed via the ui
in which case, you want to match the ui and use render.transaction
s
Yes, the HTML version is a button on the UI that opens the suitelet
b
you are trying to match the output of some sort of html. You never shared how you got that html, which is why i assumed it was printed from the ui. The html that generates the button that opens your suitelet is not related to that html that you are trying to match
n
Unless the template file used is a copy of the freemarker that's used by the print button and saved in the filecabinet...
b
there is a difference between the data used by netsuite when printing a record and the data used by adding a record to a renderer
s
my code was based on the the example in the docs , how would render.transaction work for using custom template (different from what is being used for the native print )
Copy code
function(render, file, record) {
        function renderRecordToPdfWithTemplate() {
            var xmlTemplateFile = file.load('Templates/PDF Templates/invoicePDFTemplate.xml');
            var renderer = render.create();
            renderer.templateContent = xmlTemplateFile.getContents();
            renderer.addRecord('record', record.load({
                type: record.Type.INVOICE,
                id: 37
            }));
            var invoicePdf = renderer.renderAsPdf();
        }
b
Choose to use the only documented parameter in the method that sounds like it could help