- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 03:11 AM
How can I automatically generate a PDF with requested item details when the state changes to "Closed Complete" and automatically send it via email?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 04:36 AM - edited ‎03-31-2025 04:38 AM
I just tried the background script below, and it successfully created an attachment in the specified RITM.
You can create a Business Rule with the condition set to trigger when the state changes to 'Closed Complete'. Add similar code to the Business Rule, and it will attach the PDF to the RITM ticket. This makes it easy to include the attachment in notifications.
var requestedItemSysId = '4279ab84833452103bd3cfc0deaad308'; // Replace with your requested item sys_id
var gr = new GlideRecord('sc_req_item');
if (gr.get(requestedItemSysId)) {
var html = '<h1>Requested Item Details</h1>';
html += '<p><strong>Number:</strong> ' + gr.number + '</p>';
html += '<p><strong>Short Description:</strong> ' + gr.short_description + '</p>';
html += '<p><strong>Description:</strong> ' + gr.description + '</p>';
// Add more fields as needed
var pdfAPI = new sn_pdfgeneratorutils.PDFGenerationAPI();
var pdfSysId = pdfAPI.convertToPDF(html, 'sc_req_item', requestedItemSysId, 'Requested_Item_Details.pdf');
if (pdfSysId) {
// Attach the PDF to the record
var attachment = new GlideSysAttachment();
attachment.write('sc_req_item', requestedItemSysId, 'Requested_Item_Details.pdf', pdfSysId);
gs.log('PDF generated and attached successfully.');
} else {
gs.error('PDF generation failed.');
}
} else {
gs.error('Requested item not found.');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 03:42 AM
Hello @Aditya Bashyam
1. Using Flow - you can use "Export Record - Flow Action".
2. Another option - using event triggered email when state changes to "closed complete".
Please check below link
https://www.servicenow.com/community/itsm-forum/attach-pdf-to-email-notification/m-p/2567121/page/2
--
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 04:29 AM
I'm just thinking—who do you want to send the email to? Think about it for a minute. If 5 requests are completed, do you want to send those 5 requests in a PDF? If so, how many emails will go out in an hour, and will the recipients even read those emails? I'm not sure what the exact use case is here.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 04:36 AM - edited ‎03-31-2025 04:38 AM
I just tried the background script below, and it successfully created an attachment in the specified RITM.
You can create a Business Rule with the condition set to trigger when the state changes to 'Closed Complete'. Add similar code to the Business Rule, and it will attach the PDF to the RITM ticket. This makes it easy to include the attachment in notifications.
var requestedItemSysId = '4279ab84833452103bd3cfc0deaad308'; // Replace with your requested item sys_id
var gr = new GlideRecord('sc_req_item');
if (gr.get(requestedItemSysId)) {
var html = '<h1>Requested Item Details</h1>';
html += '<p><strong>Number:</strong> ' + gr.number + '</p>';
html += '<p><strong>Short Description:</strong> ' + gr.short_description + '</p>';
html += '<p><strong>Description:</strong> ' + gr.description + '</p>';
// Add more fields as needed
var pdfAPI = new sn_pdfgeneratorutils.PDFGenerationAPI();
var pdfSysId = pdfAPI.convertToPDF(html, 'sc_req_item', requestedItemSysId, 'Requested_Item_Details.pdf');
if (pdfSysId) {
// Attach the PDF to the record
var attachment = new GlideSysAttachment();
attachment.write('sc_req_item', requestedItemSysId, 'Requested_Item_Details.pdf', pdfSysId);
gs.log('PDF generated and attached successfully.');
} else {
gs.error('PDF generation failed.');
}
} else {
gs.error('Requested item not found.');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 06:16 AM