Skip to content

Commit 5770383

Browse files
authored
Feature/pdf generator (#2388)
* Add README for PDF generation using PDFGenerationAPI * Add PDF generation for related incidents Implement PDF generation for incidents related to a change request using ServiceNow's PDFGenerationAPI. * Update README with example image for PDF generation Added example image to README for PDF generation. * Add introduction section to PDF generation README Added an introduction section to the README for clarity.
1 parent 6393743 commit 5770383

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Introduction
2+
Generating a PDF using PDFGenerationAPI
3+
Calling an OOTB convertToPDFWithHeaderFooter() method to generate a PDF with your header and footer.
4+
PDFGenerationAPI – convertToPDFWithHeaderFooter(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration)
5+
6+
# Example:
7+
<img width="704" height="496" alt="image" src="https://github.com/user-attachments/assets/9d086ee3-db76-482d-ab11-4b0540a5e2fb" />
8+
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//Table: Change Request
2+
// UI action button on the change form that exports all the related incidents into a PDF format.
3+
//ServiceNows PDFGenerationAPI allows you to customize the page size, header, footer, header image, page orientation, and more.
4+
5+
var inc = new GlideRecord('incident'),
6+
incidentsList = [],
7+
v = new sn_pdfgeneratorutils.PDFGenerationAPI,
8+
html = '',
9+
hfInfo = new Object(),
10+
result;
11+
inc.addQuery('rfc', current.sys_id);
12+
inc.query();
13+
while (inc.next()) {
14+
incidentsList.push(inc.number);
15+
incidentsList.push(inc.getDisplayValue('caller_id'));
16+
incidentsList.push(inc.getDisplayValue('category'));
17+
incidentsList.push(inc.getDisplayValue('subcategory'));
18+
incidentsList.push(inc.getValue('priority'));
19+
incidentsList.push(inc.getValue('short_description'));
20+
incidentsList.push(inc.getValue('description'));
21+
incidentsList.push(inc.getDisplayValue('assignment_group'));
22+
}
23+
var json = {
24+
incidents: incidentsList.toString()
25+
};
26+
27+
JSON.stringify(json);
28+
html = '<h1 style="margin: 0in; text-align: center; line-height: 107%; break-after: avoid; font-size: 20pt; font-family: Calibri Light, sans-serif; color: #2e74b5; font-weight: normal;" align="center"><strong><span style="font-size: 16.0pt; line-height: 107%; font-family: Arial Narrow, sans-serif; color: #002060;">Incidents Related to the Change: ' + current.number + ' </span></strong></h1><br>';
29+
30+
31+
html += '<div style="width: 100%"><p><strong><span style="font-size: 11pt; font-family: Arial Arrow; color: #002060;">Incidents List</span><span style="font-size: 2pt; font-family: Palatino; color: #002060;">&nbsp;&nbsp;</span></strong></p></div>';
32+
html += '<table style="table-layout: fixed; width: 100%; border-collapse: collapse;" border="1"><tr style="text-align: center;background-color: #B4C6E7;font-size: 10pt; font-family: Arial Arrow; word-wrap: break-word;"><td><strong>Number</strong></td><td><strong>Caller</strong></td><td><strong>Category</strong></td><td><strong>Sub Category</strong></td><td><strong>Priority</strong></td><td><strong>Short Description</strong></td><td><strong>Description</strong></td><td><strong>Assignment Group</strong></td></tr>' + getIncidentsTable(json.incidents) + '</table>';
33+
hfInfo["FooterTextAlignment"] = "BOTTOM_CENTER";
34+
hfInfo["FooterText"] = "Incidents List";
35+
hfInfo["PageOrientation"] = "LANDSCAPE";
36+
hfInfo["GeneratePageNumber"] = "true";
37+
38+
result = v.convertToPDFWithHeaderFooter(html, 'change_request', current.sys_id, "Incidents Related to the Change:_" + current.number, hfInfo);
39+
action.setRedirectURL(current);
40+
41+
function getIncidentsTable(incidents) {
42+
if (incidents == '')
43+
return '';
44+
var table = '',
45+
i;
46+
incidents = incidents.split(',');
47+
for (i = 0; i < incidents.length; i += 8)
48+
table += '<tr style="text-align: center;font-size: 10pt; font-family: Arial Arrow; word-wrap: break-word;"><td>' + incidents[i] + '</td><td>' + incidents[i + 1] + '</td><td>' + incidents[i +2] + '</td><td>' + incidents[i + 3] + '</td><td>' + incidents[i + 4] + '</td><td>' + incidents[i + 5] + '</td><td>' + incidents[i + 6] + '</td><td>' + incidents[i + 7] + '</td></tr>';
49+
return table;
50+
}

0 commit comments

Comments
 (0)