The CreatorCon Call for Content is officially open! Get started here.

Issue with PDF Generated via External API Call in ServiceNow: Formatting Issues and Corrupted Charts

prasanna16
Tera Contributor

Hi,

 

I am encountering an issue with a PDF generated by an external API call invoked through a Script Include in ServiceNow. The returned PDF has formatting issues, such as misaligned text or disrupted layout, and the charts within the PDF are corrupted (e.g., distorted visuals, missing elements, or improper rendering).

 

 
        try {
            var attachmentGR = new GlideSysAttachment();
            var targetGR = new GlideRecord('x_ydllc_tavro_comp_frameworks');
            if (targetGR.get(inputs.recordId)) {
                var pdfResult = attachmentGR.write(targetGR, 'assessment_report.pdf', 'application/pdf',apiResponse.body);
                if (!pdfResult) {
                    gs.error('Failed to attach PDF to record ' + inputs.recordId + ' in table x_ydllc_tavro_comp_frameworks');
                    return 'error: Failed to attach PDF';
                }
                gs.info('Successfully attached PDF to record ' + inputs.recordId);
            } else {
                gs.error('Record not found for sys_id ' + inputs.recordId + ' in table x_ydllc_tavro_comp_frameworks');
                return 'error: Record not found';
            }
        } catch (e) {
            gs.error('Error attaching PDF: ' + e.message);
            return 'error: PDF attachment failed - ' + e.message;
        }
0 REPLIES 0