- 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 04:38 AM
do you want PDF to be generated with the RITM variables and send it over email?
you can use PDF Generation API and then attach and then send email.
check this link which has script from Piyush
Generate PDF file for catalog variables and attach it to RITM
you can check the PDF Generation API for this
Generating Custom PDFs - using the new PDFGenerationAPI
another method
Generate PDF and attach to the record
When catalog item is submitted, attach variables to RITM as a PDF
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2025 04:39 AM
Hi @Aditya Bashyam ,
you can refer this link also https://www.servicenow.com/community/developer-forum/generate-pdf-document-action-in-flow-designer/m...