HTML to PDF API leads to 'Out of memory' errors when the HTML file is a lengthy nested HTML file.Description☞ "Generate PIR PDF" Business rule (sys_id : 2237f329df10220068c32df36bf263b3) gets triggered after an update on a security incident in sn_si_incident. ☞ This business rule calls an API to convert HTML to PDF and when the HTML file is a lengthy nested HTML file or an invalid html. This is resulting in 'Out of memory' errors and nodes being unresponsive. ☞ The"Generate PIR PDF" Business rule (sys_id : 2237f329df10220068c32df36bf263b3) calles Script Include "ReportTemplateUtil" (sys_id : eb14110ac7571010603cb51927c26058) Sample Stack trace: Build tag: glide-tokyo-07-08-2022__patch7a-03-27-2023main,glide.scheduler.worker.4,4com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:338)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getProperty(AbstractRenderer.java:335)com.itextpdf.layout.renderer.AbstractRenderer.getPropertyAsBoolean(AbstractRenderer.java:436)com.itextpdf.layout.renderer.AbstractRenderer.isKeepTogether(AbstractRenderer.java:2193)com.itextpdf.layout.renderer.AbstractRenderer.isKeepTogether(AbstractRenderer.java:2189)com.itextpdf.layout.renderer.AbstractRenderer.updateHeightsOnSplit(AbstractRenderer.java:2061)com.itextpdf.layout.renderer.AbstractRenderer.updateHeightsOnSplit(AbstractRenderer.java:2043)com.itextpdf.layout.renderer.BlockRenderer.processNotFullChildResult(BlockRenderer.java:825)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:314)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.BlockRenderer.layout(BlockRenderer.java:243)com.itextpdf.layout.renderer.TableRenderer.layout(TableRenderer.java:592)com.itextpdf.layout.renderer.RootRenderer.addChild(RootRenderer.java:141)com.itextpdf.html2pdf.attach.impl.layout.HtmlDocumentRenderer.addChild(HtmlDocumentRenderer.java:176)com.itextpdf.layout.RootElement.createAndAddRendererSubTree(RootElement.java:367)com.itextpdf.layout.RootElement.addElement(RootElement.java:376)com.itextpdf.layout.RootElement.add(RootElement.java:105)com.itextpdf.layout.Document.add(Document.java:140)com.itextpdf.html2pdf.attach.impl.tags.HtmlTagWorker.processBlockChild(HtmlTagWorker.java:189)com.itextpdf.html2pdf.attach.impl.tags.HtmlTagWorker.processTagChild(HtmlTagWorker.java:155)com.itextpdf.html2pdf.attach.impl.tags.BodyTagWorker.processTagChild(BodyTagWorker.java:127)com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.visit(DefaultHtmlProcessor.java:370)com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.visit(DefaultHtmlProcessor.java:352)com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.visit(DefaultHtmlProcessor.java:352)com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor.processDocument(DefaultHtmlProcessor.java:260)com.itextpdf.html2pdf.attach.Attacher.attach(Attacher.java:78)com.itextpdf.html2pdf.HtmlConverter.convertToDocument(HtmlConverter.java:351)com.snc.pdfgenerator.ITextPDFGenerationService.htmlToPdfConvertV1(ITextPDFGenerationService.java:340)com.snc.pdfgenerator.ITextPDFGenerationService.convertToPDF(ITextPDFGenerationService.java:196)com.snc.pdfgenerator.ITextPDFGenerationService.convertToPDF(ITextPDFGenerationService.java:326)com.snc.pdfgenerator.ITextPDFGenerationService.convertToPDFAndAttach(ITextPDFGenerationService.java:92)com.snc.pdfgenerator.PDFGenerationService.convertToPDF(PDFGenerationService.java:126)com.snc.pdfgenerator.PDFGenerationAPI.convertToPDF(PDFGenerationAPI.java:105)com.snc.pdfgenerator.PDFGenerationAPI.jsFunction_convertToPDFWithHeaderFooter(PDFGenerationAPI.java:112)java.base@11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)java.base@11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)java.base@11.0.16.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)java.base@11.0.16.1/java.lang.reflect.Method.invoke(Method.java:566)org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138)org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:677)org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614)org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2649)org.mozilla.javascript.optimizer.OptRuntime.callN(OptRuntime.java:52)org.mozilla.javascript.gen.sys_script_include_eb14110ac7571010603cb51927c26058_script_8475._c_anonymous_26(sys_script_include.eb14110ac7571010603cb51927c26058.script:548)org.mozilla.javascript.gen.sys_script_include_eb14110ac7571010603cb51927c26058_script_8475.call(sys_script_include.eb14110ac7571010603cb51927c26058.script)org.mozilla.javascript.ScriptRuntime.doCall2(ScriptRuntime.java:2734)org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2657)org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1518)org.mozilla.javascript.Interpreter.interpret(Interpreter.java:830)org.mozilla.javascript.InterpretedFunction.lambda$call$0(InterpretedFunction.java:160)org.mozilla.javascript.InterpretedFunction$$Lambda$322/0x5fefee28.get(Unknown Source)com.glide.script.ScriptCaller$$Lambda$323/0x5fefe228.call(Unknown Source)com.glide.caller.gen.sys_script_2237f329df10220068c32df36bf263b3_script.call(Unknown Source)com.glide.script.ScriptCaller.call(ScriptCaller.java:18)org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:159)org.mozilla.javascript.ScriptRuntime.doCall2(ScriptRuntime.java:2734)org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2657)org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1518)org.mozilla.javascript.Interpreter.interpret(Interpreter.java:830)org.mozilla.javascript.InterpretedFunction.lambda$exec$1(InterpretedFunction.java:176)org.mozilla.javascript.InterpretedFunction$$Lambda$348/0x5fff8828.get(Unknown Source)com.glide.script.ScriptCaller$$Lambda$323/0x5fefe228.call(Unknown Source)com.glide.caller.gen.sys_script_2237f329df10220068c32df36bf263b3_script.call(Unknown Source)com.glide.script.ScriptCaller.call(ScriptCaller.java:18)org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:397)com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:209)com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:137)com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:348)com.glide.script.BusinessRule.runScript(BusinessRule.java:443)com.glide.script.BusinessRule.runSyncBusinessRule(BusinessRule.java:324)com.glide.script.BusinessRule.runBusinessRule(BusinessRule.java:217) Sample logs: 2023-06-09 11:02:53 (156) worker.4 worker.4 txid=0eec560e1b5b *** Script: SIR1426072: State changed (Review->Closed), setting task to inactive 2023-06-09 11:03:02 (813) worker.4 worker.4 txid=0eec560e1b5b com.snc.pdfgenerator.PDFGenerationService - Html to PDF conversion, target table name : sn_si_incident, sysId : 408e2fcf1bc7e5142f99eb9fe54bcb56, request ID : 9dfc5a0e1b5b2d582f99eb9fe54bcb33 2023-06-09 11:03:03 (014) worker.4 worker.4 txid=0eec560e1b5b WARNING *** WARNING *** Get for non-existent record: sys_pdf_generation_font_family:undefined, initializing 2023-06-09 11:03:03 (264) worker.4 worker.4 txid=0eec560e1b5b com.snc.pdfgenerator.PdfUtil - Adding fonts locations for PDF generation took time_ms=231☞ In the above example, security incident : SIR1426072 state changed to closed, which triggered : "com.snc.pdfgenerator.PDFGenerationService - Html to PDF conversion" calling "Generate PIR PDF" Business rule. ResolutionWorkaround: Note that the work around is given by "Dev-Platform DocViewer team". So please work with "Dev-Platform DocViewer team" through a task for any questions or concerns: ☞ Please delete the Line 548. You can find it here: https://<instance>.service-now.com/sys_script_include.do?sys_id=eb14110ac7571010603cb51927c26058&sysparm_record_target=sys_script_include&sysparm_record_row=1&sysparm_record_rows=1&sysparm_record_list=sys_idSTARTSWITHeb14110ac7571010603cb51927c26058%5EORDERBYnameDelete Line 548: var result = (new sn_pdfgeneratorutils.PDFGenerationAPI()).convertToPDFWithHeaderFooter(docBody, tableName, sysId, fileName, map);☞ we need to add below two extra parameters and their corresponding values to the script.Please copy & paste the below 4 lines after deleting the Line 548 at the same place. var docConfig = new Object(); docConfig["page_number_config"] = "afd4fc91c7023010da58d25827c26092"; // Taken from the doc_page_number_config Table var fontFamilySysID = ""; // note: A new record needs to be added in the sys_pdf_generation_font_family table if we need any specific font to be shown in the PDF. Once a new record is created, copy the sysID and pass it through this parameter as fontFamilySysID else keep it empty.var result = (new sn_pdfgeneratorutils.PDFGenerationAPI()).convertToPDFWithHeaderFooter(docBody, tableName, sysId, fileName, map, fontFamilySysID, docConfig);