Generate PDF from multiple records, with customized design
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2019 06:11 AM
Hello guys,
I have got to generate a PDF with contents from multiple records and customize its design/template to meet customers needs. I have spent several hours googling and I am out of ideas atm.
I am stuck at the PDF generation part.
I know there is OOB functionality Export directly from URL which can export any record or list by typing '?PDF' after the '.do', but there is no way (or tell me I am wrong) how to customize this generic 'form-like' looking template, also it can export only one record/list at a time.
Also, I have found generalPDF class (Script Include), which is global but restricted to global only (huh?) and then another class GeneralPdfUtils which is global and accessible from all scopes, but I have no idea how to use this one as there is no documentation nor comments and from the method names I have a general vibe its a no-use for my case.
My approach is sth like:
- code an UI page with appropiate html mark up and CSS media queries so its meets the branding and layout requirements
- fill in the UI page on the fly with data each time it is called (query the records smh via URL)
- make a "snapshot" of the UI page and export it to PDF
- fetch the PDF and append it to a record
Currently I am struggling to generate custom PDF in ServiceNow UI16.
I am restricted to scripting and/or OOB functionality, no 3rd party libraries, rest calls and definitely no paid plugins.
ANY ideas are welcomed and appreciated in advance!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 07:42 PM
You can customize any of the buttons or widgets to generate information for multiple records for a PDF. For the specific script that can be used to reference in a server GwtExportScheduleDialog object with parameters based off of custom functionality within a server script.
function runContextAction() { var sysparm_rows = g_list.grandTotalRows; var num_rows = parseInt(sysparm_rows); var sysparm_query = "change_request.sys_id=" + g_form.getUniqueValue();//add in your own sysparam query here you can get this from the URL when you do your own query var sysparm_view = g_list.view; if (num_rows < g_export_warn_threshold) { var dialog = new GwtPollDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf+'); dialog.execute(); return; } var dialog = new GwtExportScheduleDialog(g_list.tableName, sysparm_query, sysparm_rows, sysparm_view, 'unload_pdf+'); dialog.execute(); }
This can be referenced in any widget or form action, etc.