How to create a PDF of the custom record based on the designed PDF template.

function generatePdf(newRecord) {
            try {
                let customId = newRecord.id
                let xmlTmplFile = file.load({ id: TEMPLATE_ID });
                let myFile = render.create();
                myFile.templateContent = xmlTmplFile.getContents();
                myFile.addRecord('record', record.load({
                    type: 'customrecord_jj_business_details',
                    id: newRecord.id
                }));
                let customPdf = myFile.renderAsPdf();
                let fileObj = file.create({
                    name: `Business Details_${customId}.pdf`, // Name of the PDF file
                    fileType: file.Type.PDF,
                    contents: customPdf.getContents(),
                    folder: FOLDER_ID
                });
                let fileId = fileObj.save();
                return fileId;
            }
            catch (err) {
                log.error("error@generatePdf", err);
                return null;
            }
        }

Leave a comment

Your email address will not be published. Required fields are marked *