Has anyone been having troubles with PDF files sin...
# defects
b
Has anyone been having troubles with PDF files since 2023.1? This is a simplified example I pulled together to isolate the error. The XML generates but the file.create fails with an unexpected error. I can create a text file just fine, but not a PDF file. The same PDF template generates with no issue when using the standard print functionality. This is used in a script that does a lot more than I'm doing here so I can't stop using the renderer, I just wanted to be sure to get down to the basics with as much standard functionality as possible. This is happening in two accounts (dev/demo account and production account)
Copy code
try {
        const rec = record.load({ type: record.Type.INVOICE, id: 5739 });
        const renderer = render.create();
        renderer.addRecord({ record: rec, templateName: 'record' });
        renderer.setTemplateById({ id: 106 });
        log.debug({title: 'Renderer created', details: ''});
        const xml = renderer.renderAsString();
        log.debug({title: 'XML created', details: xml});

        const pdf = file.create({ fileType: file.Type.PDF, name: `demoPDF.pdf`, contents: xml });
        log.debug({title: 'File created', details: pdf});

        pdf.folder = 11397;
        const fileId = pdf.save();
        log.debug({ title: 'Saved ID - Direct PDF', details: fileId });
      } catch (e) {
          log.error({ title: 'Caught Error in PDF save - direct pdf', details: e });
      }
e
Does your source data have ampersands or < > included in them?
b
No, good thought, but it's all pretty simple data. It was working in 22.2 and broke in 23.1
d
I might be missing something, but why not use
renderAsPdf()
which returns a
file.File
directly (rather than using
file.create
using the xml as contents)?
b
🤬 Fair point, it’s someone else’s code that’s been in prod and working fine for a while and I was too stuck on “it worked before, why doesn’t it work now”. Re-reading file.create, it does say that the contents of a binary file must be base64 encoded, I tried that but it probably wants them to actually be rendered to base64. I’m away from my computer but will switch to renderAsPdf later this evening. Thanks @David B
Now I feel stupid, but that’s how we learn
👍 1
d
eh 🤷 I just hope it solves the issue =]
b
So the example I posted was from my testing, which I've realized was a bad representation. The full solution is retrieving a PDF from a Suitelet and saving it. I had misread it as returning XML from the Suitelet. Back to the drawing board for me
Your comments did trigger some thoughts though, so I'll play with it some more.
If anyone is curious. What was working before 23.1: PDF was being generated in the Suitelet and was being returned in the Suitelet response and then saved in the Scheduled Script. What we changed to work around: PDF is now being saved in the Suitelet and only the ID is being returned to the scheduled script. I believe there's still a defect in the file module with file.create not working from a PDF binary string or in the https.post handling the response from the Suitelet properly. We were able to confirm the Suitelet worked from the UI (we could download the PDF) but did not work in the scheduled script.
d
that is interesting. maybe something you could log with NetSuite? Did you log the response the scheduled script is getting from the suitelet? Wonder if, for whatever reason, it's any different when called from the UI
b
I should clarify, we do have a defect open with NetSuite now, they've acknowledged that there's something happening somewhere that they are working to resolve
I logged out the response in the script, it looks like a PDF file but I haven't done a detailed comparison