Interested in a ServiceNow event built for developers? Registration for now[dev]26 is officially open!

Custom Export PDF from Workspace Form Including Related Lists - Best Practice?

NikhilSingh22_
Tera Expert

Hi Community,

I'm looking for the best practice to implement PDF export from a Workspace record form, including related list data, without attaching the generated PDF to the record.

Requirement

From a Workspace form, users should be able to:

  • Export the current record as PDF
  • Include selected related list records in the PDF
  • Download the PDF directly
  • Avoid attaching the PDF to the record
  • Follow supported Workspace best practices

Approaches Evaluated

1. Classic URL-based PDF export

 

var url = '/' + g_form.getTableName() + '.do?sys_id=' + g_form.getUniqueValue() + '&PDF';
top.window.open(url, '_blank');

 

Issue:

  • Relies on window.open()
  • Uses global window objects
  • Not considered a modern or Workspace-friendly approach

2. Using g_navigation

g_navigation.open(url, '_blank');

Issue:

  • Works in classic UI
  • Does not appear to work in Workspace

3. Server-side PDFGenerationAPI

 

var pdfAPI = new sn_pdfgeneratorutils.PDFGenerationAPI();
var result = pdfAPI.convertToPDF(
html,
current.getTableName(),
current.getUniqueValue(),
fileName
);

 

Issue:

  • Generates the PDF successfully
  • Automatically attaches the PDF to the record
  • My requirement is to allow download without creating attachments
  • Add Custom CSS using script is a big overhead. 

4. Legacy GwtPollDialog approach

 

var dialog = new GwtPollDialog(
g_form.getTableName(),  "",  "",  "",  "unload_pdf",  "",  "",  "",  "true",  g_form.getUniqueValue(),  "",  ""
);
dialog.execute();

 

Issue:

  • Not supported in Workspace
  • Appears to be tied to classic UI components

Question

Has anyone implemented a supported Workspace solution for exporting a record attached with related list data  to PDF?

Specifically:

  1. What is the recommended approach in Workspace?
  2. Is there a supported way to generate and download a PDF without creating a record attachment?
  3. Has anyone leveraged UI Builder components, Scripted REST APIs, or a custom PDF generation framework for this requirement?
  4. Are there any OOTB Workspace capabilities I'm overlooking?

I would appreciate any recommendations, architectural guidance, or examples of successful implementations.

Thanks in advance!

Nikhil | KPMG | Associate - Consultant

0 REPLIES 0