Why is this Advanced PDF template not populating the terms from the object that I am passing to it?
up vote
0
down vote
favorite
So, basically I am trying to get the XML template for the PDF and I plan to eventually add some additional XML in the code after getting the template working in this manner. However, when I attempt to pass a data source object to the PDF it is not working. Does anyone know the cause of this issue, and what I am doing incorrectly here?
XML template (stripped out everything but the variable in the table for testing):
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<!--removed lengthy head to make code more readable-->
<body footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
<table class="body" style="width: 100%; margin-top: 10px;">
<tr>
<td>${jsonObj.terms}</td>
</tr></table>
</body>
</pdf>
Script:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/error','N/render','N/file','N/record','N/log'],
/**
* @param {error} error
*/
function(error, render, file, record, log) {
function beforeSubmit(context) {
log.debug('After submitting invoice, create advanced PDF detail layout', context);
var isInvoice = context.newRecord.type == 'invoice';
// Create advanced PDF
if (isInvoice){
log.audit('Creating invoice');
renderRecordToPdfWithTemplate(context.newRecord);
}
else{
error.create({
name: 'ERROR_RECEIVED',
message: 'Cannot create advanced PDF from this record type'
});
log.audit(error.name,error.message);
}
}
return {
beforeSubmit: beforeSubmit
};
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
/*
renderer.addRecord({
type: record.Type.INVOICE,
record: context
});
*/
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var renderXmlAsString = renderer.renderAsString();
log.debug('Added record to PDF', context);
var invoicePdf = render.xmlToPdf({
xmlString: renderXmlAsString
});
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
});
netsuite suitescript2.0 bfo
add a comment |
up vote
0
down vote
favorite
So, basically I am trying to get the XML template for the PDF and I plan to eventually add some additional XML in the code after getting the template working in this manner. However, when I attempt to pass a data source object to the PDF it is not working. Does anyone know the cause of this issue, and what I am doing incorrectly here?
XML template (stripped out everything but the variable in the table for testing):
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<!--removed lengthy head to make code more readable-->
<body footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
<table class="body" style="width: 100%; margin-top: 10px;">
<tr>
<td>${jsonObj.terms}</td>
</tr></table>
</body>
</pdf>
Script:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/error','N/render','N/file','N/record','N/log'],
/**
* @param {error} error
*/
function(error, render, file, record, log) {
function beforeSubmit(context) {
log.debug('After submitting invoice, create advanced PDF detail layout', context);
var isInvoice = context.newRecord.type == 'invoice';
// Create advanced PDF
if (isInvoice){
log.audit('Creating invoice');
renderRecordToPdfWithTemplate(context.newRecord);
}
else{
error.create({
name: 'ERROR_RECEIVED',
message: 'Cannot create advanced PDF from this record type'
});
log.audit(error.name,error.message);
}
}
return {
beforeSubmit: beforeSubmit
};
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
/*
renderer.addRecord({
type: record.Type.INVOICE,
record: context
});
*/
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var renderXmlAsString = renderer.renderAsString();
log.debug('Added record to PDF', context);
var invoicePdf = render.xmlToPdf({
xmlString: renderXmlAsString
});
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
});
netsuite suitescript2.0 bfo
1
the code looks generally right. What do you mean it is not working? Do you get output but the jsonObj value is blank? With that code you'd just be seeing a blank pdf. If you add a static value instead of referencing jsonObj does that show up in the output? Very often when dealing with BFO I find my errors are not where I think they are.
– bknights
Nov 7 at 17:49
1
I tested this exactly as you have written, except for changing the XML file ID to suit what I had when I uploaded it in my file cabinet, and it worked exactly as expected - I found the output file in the folder with ID -15 with 'test terms' in it. So as far as I can see it works as it should.
– Krypton
Nov 7 at 20:01
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So, basically I am trying to get the XML template for the PDF and I plan to eventually add some additional XML in the code after getting the template working in this manner. However, when I attempt to pass a data source object to the PDF it is not working. Does anyone know the cause of this issue, and what I am doing incorrectly here?
XML template (stripped out everything but the variable in the table for testing):
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<!--removed lengthy head to make code more readable-->
<body footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
<table class="body" style="width: 100%; margin-top: 10px;">
<tr>
<td>${jsonObj.terms}</td>
</tr></table>
</body>
</pdf>
Script:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/error','N/render','N/file','N/record','N/log'],
/**
* @param {error} error
*/
function(error, render, file, record, log) {
function beforeSubmit(context) {
log.debug('After submitting invoice, create advanced PDF detail layout', context);
var isInvoice = context.newRecord.type == 'invoice';
// Create advanced PDF
if (isInvoice){
log.audit('Creating invoice');
renderRecordToPdfWithTemplate(context.newRecord);
}
else{
error.create({
name: 'ERROR_RECEIVED',
message: 'Cannot create advanced PDF from this record type'
});
log.audit(error.name,error.message);
}
}
return {
beforeSubmit: beforeSubmit
};
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
/*
renderer.addRecord({
type: record.Type.INVOICE,
record: context
});
*/
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var renderXmlAsString = renderer.renderAsString();
log.debug('Added record to PDF', context);
var invoicePdf = render.xmlToPdf({
xmlString: renderXmlAsString
});
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
});
netsuite suitescript2.0 bfo
So, basically I am trying to get the XML template for the PDF and I plan to eventually add some additional XML in the code after getting the template working in this manner. However, when I attempt to pass a data source object to the PDF it is not working. Does anyone know the cause of this issue, and what I am doing incorrectly here?
XML template (stripped out everything but the variable in the table for testing):
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<!--removed lengthy head to make code more readable-->
<body footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
<table class="body" style="width: 100%; margin-top: 10px;">
<tr>
<td>${jsonObj.terms}</td>
</tr></table>
</body>
</pdf>
Script:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/error','N/render','N/file','N/record','N/log'],
/**
* @param {error} error
*/
function(error, render, file, record, log) {
function beforeSubmit(context) {
log.debug('After submitting invoice, create advanced PDF detail layout', context);
var isInvoice = context.newRecord.type == 'invoice';
// Create advanced PDF
if (isInvoice){
log.audit('Creating invoice');
renderRecordToPdfWithTemplate(context.newRecord);
}
else{
error.create({
name: 'ERROR_RECEIVED',
message: 'Cannot create advanced PDF from this record type'
});
log.audit(error.name,error.message);
}
}
return {
beforeSubmit: beforeSubmit
};
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
/*
renderer.addRecord({
type: record.Type.INVOICE,
record: context
});
*/
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var renderXmlAsString = renderer.renderAsString();
log.debug('Added record to PDF', context);
var invoicePdf = render.xmlToPdf({
xmlString: renderXmlAsString
});
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
});
netsuite suitescript2.0 bfo
netsuite suitescript2.0 bfo
edited Nov 7 at 12:56
asked Nov 7 at 12:42
Jordan Johnson
64211233
64211233
1
the code looks generally right. What do you mean it is not working? Do you get output but the jsonObj value is blank? With that code you'd just be seeing a blank pdf. If you add a static value instead of referencing jsonObj does that show up in the output? Very often when dealing with BFO I find my errors are not where I think they are.
– bknights
Nov 7 at 17:49
1
I tested this exactly as you have written, except for changing the XML file ID to suit what I had when I uploaded it in my file cabinet, and it worked exactly as expected - I found the output file in the folder with ID -15 with 'test terms' in it. So as far as I can see it works as it should.
– Krypton
Nov 7 at 20:01
add a comment |
1
the code looks generally right. What do you mean it is not working? Do you get output but the jsonObj value is blank? With that code you'd just be seeing a blank pdf. If you add a static value instead of referencing jsonObj does that show up in the output? Very often when dealing with BFO I find my errors are not where I think they are.
– bknights
Nov 7 at 17:49
1
I tested this exactly as you have written, except for changing the XML file ID to suit what I had when I uploaded it in my file cabinet, and it worked exactly as expected - I found the output file in the folder with ID -15 with 'test terms' in it. So as far as I can see it works as it should.
– Krypton
Nov 7 at 20:01
1
1
the code looks generally right. What do you mean it is not working? Do you get output but the jsonObj value is blank? With that code you'd just be seeing a blank pdf. If you add a static value instead of referencing jsonObj does that show up in the output? Very often when dealing with BFO I find my errors are not where I think they are.
– bknights
Nov 7 at 17:49
the code looks generally right. What do you mean it is not working? Do you get output but the jsonObj value is blank? With that code you'd just be seeing a blank pdf. If you add a static value instead of referencing jsonObj does that show up in the output? Very often when dealing with BFO I find my errors are not where I think they are.
– bknights
Nov 7 at 17:49
1
1
I tested this exactly as you have written, except for changing the XML file ID to suit what I had when I uploaded it in my file cabinet, and it worked exactly as expected - I found the output file in the folder with ID -15 with 'test terms' in it. So as far as I can see it works as it should.
– Krypton
Nov 7 at 20:01
I tested this exactly as you have written, except for changing the XML file ID to suit what I had when I uploaded it in my file cabinet, and it worked exactly as expected - I found the output file in the folder with ID -15 with 'test terms' in it. So as far as I can see it works as it should.
– Krypton
Nov 7 at 20:01
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You don't need the renderer.renderAsString();
since you're already loading the XML from the file cabinet.
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var invoicePdf = renderer.renderAsPdf();
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You don't need the renderer.renderAsString();
since you're already loading the XML from the file cabinet.
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var invoicePdf = renderer.renderAsPdf();
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
add a comment |
up vote
1
down vote
accepted
You don't need the renderer.renderAsString();
since you're already loading the XML from the file cabinet.
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var invoicePdf = renderer.renderAsPdf();
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You don't need the renderer.renderAsString();
since you're already loading the XML from the file cabinet.
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var invoicePdf = renderer.renderAsPdf();
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
You don't need the renderer.renderAsString();
since you're already loading the XML from the file cabinet.
function renderRecordToPdfWithTemplate(context) {
var jsonObj = {
terms: "test terms"
};
var templateId = '7959'; // ID of the XML
var templateFile = file.load({id: templateId});
var renderer = render.create();
renderer.templateContent = templateFile.getContents();
renderer.addCustomDataSource({
format: render.DataSource.OBJECT,
alias: "jsonObj",
data: jsonObj
});
log.debug('Rendering as PDF');
var invoicePdf = renderer.renderAsPdf();
invoicePdf.name = 'Testpdf2.pdf';
invoicePdf.folder = -15;
try{
var fileId = invoicePdf.save();
log.debug('Saved PDF to file '+fileId);
}
catch(e){
alert('Error saving file');
log.debug('Error saving file');
debugger;
}
}
answered Nov 7 at 18:50
ehcanadian
5061818
5061818
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189688%2fwhy-is-this-advanced-pdf-template-not-populating-the-terms-from-the-object-that%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
the code looks generally right. What do you mean it is not working? Do you get output but the jsonObj value is blank? With that code you'd just be seeing a blank pdf. If you add a static value instead of referencing jsonObj does that show up in the output? Very often when dealing with BFO I find my errors are not where I think they are.
– bknights
Nov 7 at 17:49
1
I tested this exactly as you have written, except for changing the XML file ID to suit what I had when I uploaded it in my file cabinet, and it worked exactly as expected - I found the output file in the folder with ID -15 with 'test terms' in it. So as far as I can see it works as it should.
– Krypton
Nov 7 at 20:01