Hi Guys, I want to Print invoice from Suiteletscri...
# suitescript
s
Hi Guys, I want to Print invoice from Suiteletscript , here is my code when I try with this getting var renderer = render.create(); renderer.addRecord(‘record’, record.load({ type: record.Type.INVOICE, id: 3190 })); renderer.setTemplateByScriptId(“custtmpl _807_5885389_sb1_483”); context.response.writeFile(renderer.renderAsPdf()); ERROR “Missing parameters required to generate PDF”.
j
what line is throwing the error? Try splitting this up a bit.
s
this line is causing problem. context.response.writeFile(renderer.renderAsPdf());
Copy code
ERROR MSG type: "error.SuiteScriptError",
   name: "MISSING_PDF_PARAMETERS",
   message: "Missing parameters required to generate PDF",
j
OK so it’s actually
renderer.renderAsPdf()
that is the error.
can you print using that template from the UI?
s
yes, i was able to print from the UI it’s working
j
on that exact Invoice?
What happens if you try something like this instead
Copy code
var pdf = render.transaction({entityId: 3190});
(this should use default template)
s
i will try, but i have to print with customized pdf template
i tried this var pdf = render.transaction({entityId: 3190}); but not printing anything
m
@stalin athavan Do you reference any joined records in the template, for example 'User', or 'Contact' or 'Customer'. You might need to add them to the renderer as well.
c
setTemplateByScriptId takes an object w/ the property "scriptId". You are passing in just a string so its not getting your template.
s
@Michael Pope i’m trying to generate with standard customer Invoice template , which has no join in it, standard advanced pdf itself not printing
m
@stalin athavan Hmmm... As far as I'm aware, you might still need to add related records. For instance, the customer record is I believe used in the invoice standard template... if so I think it needs to be added. I can't remember though... it's been a while since I've had to do it in code.
👍 1
c
Their method call is wrong. It has nothing to do w/ adding other records.
j
what @creece is saying is that
renderer.setTemplateByScriptId("custtmpl _807_5885389_sb1_483");
needs to be
renderer.setTemplateByScriptId({scriptId: "custtmpl _807_5885389_sb1_483"});
💯 1
s
I tried using this getting this ERROR
Copy code
type: "error.SuiteScriptError",
   name: "MISSING_PDF_PARAMETERS",
   message: "Missing parameters required to generate PDF",
   stack: [
      "renderAsPdf(N/render)",
      "newTest(/SuiteScripts/printInvoices.js:219)",
      "onRequest(/SuiteScripts/printInvoices.js:153)"
   ],
   cause: {
      type: "internal error",
      code: "MISSING_PDF_PARAMETERS",
      details: "Missing parameters required to generate PDF",
      userEvent: null,
      stackTrace: [
         "renderAsPdf(N/render)",
         "newTest(/SuiteScripts/printInvoices.js:219)",
         "onRequest(/SuiteScripts/printInvoices.js:153)"
      ],
attached my script file, function which is expected to print invoice is newTest(context)
j
You have a space on line 218 that shouldn't be there.
s
@jen @creece @Michael Pope thanks everyone for your time, i have fixed working copy function printINV(context) { var fulfillmentrecord = record.load({ type: record.Type.INVOICE, id: 3190 }); var renderer = render.create(); var templateFileId = 15714; var xmlTemplateFile = file.load({ id: templateFileId }); renderer.templateContent = xmlTemplateFile.getContents(); renderer.addRecord({ templateName: ‘record’, record: fulfillmentrecord }); var pdfFile = render.xmlToPdf({ xmlString: renderer.renderAsString() }); context.response.writeFile({ file: pdfFile }); log.debug(‘printINV’, ‘xmlTemplateFile’ + JSON.stringify(renderer.renderAsPdf())); // context.response.writeFile(renderer.renderAsPdf()); }
💯 1
316 Views