Automated Document creation in HRSD from catalog form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 02:03 AM
Hi All,
We have a requirement to create a pdf document even after the creation of HR tickets, whenever the ticket is created . And the pdf file is of specific format , we need to populate data in each fields of pdf file from the catalog form.
Please guide me in proceeding with this if anyone has experience for the same.
Regards,
Devika.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 02:22 AM
Hello @Devika3,
The developer share site may provide what you need.
Specifically, Gernerate PDF created by Daniel Cordick.
His description:
A UI Action created for the incident table and designed for easy adaptation to other tables. The "Generate PDF" UI action leverages an inline HTML and the pdfgeneratorutils API to generate a PDF document and automatically attach it to the current record.
If this information was helpful, please mark this answer as Accepted as Solution and hit the helpful button. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 03:04 AM
Hi Tammy,
My requirement is somewhat different. I need to populate the pdf document with fields from the catalog form and needs to attach it to the HR ticket got created.
Regards,
Devika.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 07:11 AM
@Devika3, I would follow @Sujit Jadhav reply. Also, the below can get you started as pdf script template. Attached is the script from Daniel Cordick's ui action. You will just need to replace with your data. Once you test it out, you will see this will be pretty simple using the PDFGenerationAPI. This can be called from an an insert br. I hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-05-2024 03:14 AM
Hello @Devika3 ,
To achieve automated document creation in HR Service Delivery (HRSD) from a catalog form in ServiceNow, you can follow these general steps:
Create PDF Template: Design a PDF template with placeholders for the data you want to populate from the catalog form. You can create the PDF template using tools like Adobe Acrobat, Microsoft Word, or Google Docs. Ensure that the template is in a format that can be programmatically filled with data.
Store the PDF Template: Upload the PDF template to a location accessible within your ServiceNow instance, such as an Attachment or Document record.
Capture Form Data: Write a Business Rule, Script Include, or Client Script to capture the data entered in the catalog form. Retrieve the relevant data fields from the HR ticket record created from the catalog form.
Generate PDF: Write a server-side script (e.g., Script Include, Script Action) that dynamically populates the PDF template with the captured data. You can use server-side libraries like Apache PDFBox (Java) or PDFtk (JavaScript) to manipulate PDF files programmatically. Alternatively, you can use a third-party service or API for PDF generation.
Attach PDF to HR Ticket: Once the PDF is generated, attach it to the HR ticket record created from the catalog form. You can use the Attachment table or the Document table to store and manage the PDF file.
Send Notification: Optionally, send a notification to relevant stakeholders (e.g., HR team, requester) informing them about the document creation and providing a link to access the attached PDF.
Testing and Validation: Test the automated document creation process thoroughly to ensure that the PDF is generated correctly and contains the expected data. Validate that the PDF format meets the requirements specified by your organization.
Here's a high-level example of how you can implement these steps:
// Example script to generate PDF and attach it to HR ticket record
// 1. Retrieve data from HR ticket record (replace with actual field names)
var ticket = new GlideRecord('hr_ticket');
if (ticket.get(current.sys_id)) {
var employeeName = ticket.employee.name;
var startDate = ticket.start_date;
// Retrieve other relevant fields...
// 2. Generate PDF using a PDF generation library or service
var pdfData = generatePDF(employeeName, startDate /*, other data fields... */);
// 3. Attach PDF to HR ticket record
var attachment = new GlideRecord('sys_attachment');
attachment.initialize();
attachment.table_name = 'hr_ticket';
attachment.file_name = 'HR_Document.pdf';
attachment.content_type = 'application/pdf';
attachment.table_sys_id = ticket.sys_id;
attachment.addEncodedQuery('file_name=HR_Document.pdf');
attachment.write(pdfData);
}
Please mark my answer Correct/Helpful, If applicable
Regards,
Sujit