#javascript #html #mapreduce #netsuite #suitescript2.0
Вопрос:
Я работаю в suitescript 2.1.
Моя цель-отправить объект, содержащий данные, необходимые модулю N/render, чтобы получить PDF-файл из шаблона, заполненного всеми данными в моем сценарии Map/Reduce.
Моим ожидаемым результатом было бы отправить электронное письмо на мой почтовый ящик с PDF-файлом и всем его содержимым. Мне удалось отправить электронное письмо с PDF-файлом hello world. Я думаю, что проблема связана с тем, как я устанавливаю свой шаблон, но я не могу быть уверен. Это ошибка, которую я получаю:
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.
Это моя функция :
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,
});
Это мой шаблон, в настоящее время в шаблоне нет полей, я проверял, работает ли он
<?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:
Проблема заключалась в этой строке :
renderer.templateContent = templateId;
Правильный способ сделать это — :
renderer.templateContent = templateId.getContents();