diff --git a/Client-Side Components/UI Actions/Generate a PDF/README.md b/Client-Side Components/UI Actions/Generate a PDF/README.md new file mode 100644 index 0000000000..2a61438b92 --- /dev/null +++ b/Client-Side Components/UI Actions/Generate a PDF/README.md @@ -0,0 +1,8 @@ +# Introduction +Generating a PDF using PDFGenerationAPI +Calling an OOTB convertToPDFWithHeaderFooter() method to generate a PDF with your header and footer. +PDFGenerationAPI – convertToPDFWithHeaderFooter(String html, String targetTable, String targetTableSysId, String pdfName, Object headerFooterInfo, String fontFamilySysId, Object documentConfiguration) + +# Example: +image + diff --git a/Client-Side Components/UI Actions/Generate a PDF/serverscript.js b/Client-Side Components/UI Actions/Generate a PDF/serverscript.js new file mode 100644 index 0000000000..66c8378e1c --- /dev/null +++ b/Client-Side Components/UI Actions/Generate a PDF/serverscript.js @@ -0,0 +1,50 @@ +//Table: Change Request +// UI action button on the change form that exports all the related incidents into a PDF format. +//ServiceNows PDFGenerationAPI allows you to customize the page size, header, footer, header image, page orientation, and more. + +var inc = new GlideRecord('incident'), + incidentsList = [], + v = new sn_pdfgeneratorutils.PDFGenerationAPI, + html = '', + hfInfo = new Object(), + result; +inc.addQuery('rfc', current.sys_id); +inc.query(); +while (inc.next()) { + incidentsList.push(inc.number); + incidentsList.push(inc.getDisplayValue('caller_id')); + incidentsList.push(inc.getDisplayValue('category')); + incidentsList.push(inc.getDisplayValue('subcategory')); + incidentsList.push(inc.getValue('priority')); + incidentsList.push(inc.getValue('short_description')); + incidentsList.push(inc.getValue('description')); + incidentsList.push(inc.getDisplayValue('assignment_group')); +} +var json = { + incidents: incidentsList.toString() +}; + + JSON.stringify(json); +html = '

Incidents Related to the Change: ' + current.number + '


'; + + +html += '

Incidents List  

'; +html += '' + getIncidentsTable(json.incidents) + '
NumberCallerCategorySub CategoryPriorityShort DescriptionDescriptionAssignment Group
'; +hfInfo["FooterTextAlignment"] = "BOTTOM_CENTER"; +hfInfo["FooterText"] = "Incidents List"; +hfInfo["PageOrientation"] = "LANDSCAPE"; +hfInfo["GeneratePageNumber"] = "true"; + +result = v.convertToPDFWithHeaderFooter(html, 'change_request', current.sys_id, "Incidents Related to the Change:_" + current.number, hfInfo); +action.setRedirectURL(current); + +function getIncidentsTable(incidents) { + if (incidents == '') + return ''; + var table = '', + i; + incidents = incidents.split(','); + for (i = 0; i < incidents.length; i += 8) + table += '' + incidents[i] + '' + incidents[i + 1] + '' + incidents[i +2] + '' + incidents[i + 3] + '' + incidents[i + 4] + '' + incidents[i + 5] + '' + incidents[i + 6] + '' + incidents[i + 7] + ''; + return table; +}