Create Custom Document : Attached it to the current record and Send Over the email to assignment Group.
Use Case 1:-
On clicking a button on the requested item form Create the custom PDF document of the Requested Item form fields and Attached that to the current RITM record.
Solution:-
Steps:-
1. Create one email template in the ‘sysevent_email_template’ table.
Fig. Email Template
2. Create the UI action on the ‘sc_req_item’ table and past the below code:-
var getTemplate = new GlideRecord("sysevent_email_template");getTemplate.addQuery("sys_id", "57c93b6d2f2201501a5cf3ecf699b631");getTemplate.query();if (getTemplate.next()) { var temp = getTemplate.message_html; var updatedHTML = temp.replace('ExampleReqBy', current.getDisplayValue('u_requested_by')); updatedHTML = updatedHTML.replace('ExampleReqFor', current.getDisplayValue('requested_for')); updatedHTML = updatedHTML.replace('ExampleAssgTo', current.getDisplayValue('assigned_to')); updatedHTML = updatedHTML.replace('ExampleAssgGroup', current.getDisplayValue('assignment_group')); updatedHTML = updatedHTML.replace('ExampleShortDes', current.getDisplayValue('short_description')); updatedHTML = updatedHTML.replace('ManagerOfAssigmentGroup', current.getDisplayValue('assignment_group.manager'));} var v = new sn_pdfgeneratorutils.PDFGenerationAPI;var result = v.convertToPDF(updatedHTML, "sc_req_item", current.sys_id, "Excel Template");
Use Case 2:-
When RITM is created and the Assignment Group of RITM is not empty then send the notification to the Assignment Group Members with the RITM custom document and attached the same document to the Current RITM.
Solution:-
Steps:-
1. Create one email template in the ‘sysevent_email_template’ table.
Fig. Email Template
2. Write down the email script as below:-
(function runMailScript( /* GlideRecord / current, / TemplatePrinter / template, / Optional EmailOutbound / email, / Optional GlideRecord / email_action, / Optional GlideRecord */ event) { // Add your code here var getTemplate = new GlideRecord("sysevent_email_template"); getTemplate.addQuery("sys_id", "57c93b6d2f2201501a5cf3ecf699b631"); getTemplate.query(); if (getTemplate.next()) { var temp = getTemplate.message_html; var updatedHTML = temp.replace('ExampleReqBy', current.getDisplayValue('u_requested_by')); updatedHTML = updatedHTML.replace('ExampleReqFor', current.getDisplayValue('requested_for')); updatedHTML = updatedHTML.replace('ExampleAssgTo', current.getDisplayValue('assigned_to')); updatedHTML = updatedHTML.replace('ExampleAssgGroup', current.getDisplayValue('assignment_group')); updatedHTML = updatedHTML.replace('ExampleShortDes', current.getDisplayValue('short_description')); updatedHTML = updatedHTML.replace('ManagerOfAssigmentGroup', current.getDisplayValue('assignment_group.manager')); } var v = new sn_pdfgeneratorutils.PDFGenerationAPI; var result = v.convertToPDF(updatedHTML, "sc_req_item", current.sys_id, "Excel Template"); var attach = new GlideRecord('sys_attachment'); attach.orderByDesc('sys_created_on'); attach.addQuery('file_name', 'Excel Template.pdf'); attach.query(); if (attach.next()) { template.print('' + "Excel Template" + ''); }})(current, template, email, email_action, event);
3. Create the notification and call the email script in it as below:-
Fig. Email Notification
Final Output Document:-
Fig. RITM Custom PDF Document
Email Notification Output:-
Fig. Email Output
If you don't want to go through all the steps then find below attached update set file.
Please mark my article as helpful and bookmark it for future use.
Regards,
Gunjan Kiratkar
Consultant - ServiceNow, Cloudaction
Rising Star 2022
https://www.servicenow.com/community/developer-articles/create-custom-document-attached-it-to-the-current-record-and/ta-p/2297295