|
| 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;"> </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