1

I'm working in suitescript 2.1.

My goal is to send an object containing the data needed by the N/render module to get a PDF file from a template filled with all the data in my Map/Reduce script.

My expected result would be to get an email sent to my mailbox with the PDF and all its content. I did manage to send an email with a hello world pdf. I think the problem comes from the way I'm setting my template but I can not be sure. This is the error i get:

execute on com.sun.proxy.$Proxy954.setTemplate failed due to: Cannot convert '{id: accessor, size: accessor, url: accessor, path: accessor, fileType: accessor, isText: accessor, encoding: accessor, name: accessor, f...'(language: JavaScript, type: NetSuiteObject) to Java type 'java.lang.String': Invalid or lossy primitive coercion.

This is my function :

  function generatePdfFileFromRawXml(jsonObj) {
    const templateId = file.load({
      id: './QuotesMonthPDF.template.xml',
    });
    const renderer = render.create();
    renderer.templateContent = templateId;
    renderer.addCustomDataSource({
      format: render.DataSource.OBJECT,
      alias: 'JSON',
      data: jsonObj,
    });

This is my template, currently the template has no fields, I was testing if it worked

<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
    <link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
    <#if .locale == "zh_CN">
        <link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
    <#elseif .locale == "zh_TW">
        <link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
    <#elseif .locale == "ja_JP">
        <link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
    <#elseif .locale == "ko_KR">
        <link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
    <#elseif .locale == "th_TH">
        <link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
    </#if>
    <style type="text/css">table { font-size: 9pt; table-layout: fixed; width: 100%; }
th { font-weight: bold; font-size: 8pt; vertical-align: middle; padding: 5px 6px 3px; background-color: #e3e3e3; color: #333333; padding-bottom: 10px; padding-top: 10px; }
td { padding: 4px 6px; }
b { font-weight: bold; color: #333333; }
</style>
</head>
<body padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
</body>
</pdf>

1 Answers1

0

The problem was this line :

 renderer.templateContent = templateId;

The correct way to do this is :

 renderer.templateContent = templateId.getContents();