- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
I have a Record Producer in ServiceNow that captures data such as Employee Name, Employee ID, Joining Date, Department, and Salary.
The requirement is:
When the record producer is submitted, a record must be created in a custom table (say u_employee_details).
Immediately after record creation, a PDF should be generated using the same data.
The generated PDF should contain selected fields (like Employee Name, Employee ID, Salary, Joining Date) and should be attached to the created record automatically.
How will I implement this end-to-end solution in ServiceNow?
Till point 1 I am okay to create RP but how create a PDF ??
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
You can use the Flow Designer as soon as the record gets created in the table.
After that, you’ll need to use the PDF Generation API. I don’t have much experience with it, but I’m sharing a few useful links below.
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
yesterday
Hi @SandeepKSingh ,
For step 2 you could trigger an insert BR on the custom table and use the PDF API from servicenow: PDFGenerationAPI - Scoped, Global | ServiceNow Developers
But it requires some knowledge how to script these files. But it's doable.
There are some good examples on the provided page.
Good luck,
Collin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @SandeepKSingh
Create a Record Producer pointing to the custom table 'u_employee_details'.
Add variables as per your choice
Map the variables to fields in the table via producer script or variable mapping.
Example Script :-
var rec = new GlideRecord('u_employee_details');
rec.initialize();
rec.u_employee_name = producer.u_employee_name;
var newSysId = rec.insert();
Create a Business Rule on u_employee_details
table:
When: after insert
Action: Call a Script Include that generates a PDF.
....
Script Include Code I will be updating Soon.. after testing ..
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @SandeepKSingh ,
----------------------
Please try this Script Include its working on My side
------ I have use the POST which other members have posted !!-----------
var PDFGeneratorUtils = Class.create();
PDFGeneratorUtils.prototype = {
initialize: function() {},
generateEmployeePDF: function(sysId) {
var gr = new GlideRecord('u_employee_details');
if (gr.get(sysId)) {
// Prepare HTML for PDF
var html = "<h2>Employee Record</h2>" +
"<p><b>Name:</b> " + gr.u_employee_name + "</p>" +
"<p><b>ID:</b> " + gr.u_employee_id + "</p>" +
"<p><b>Joining Date:</b> " + gr.u_joining_date + "</p>" +
"<p><b>Salary:</b> " + gr.u_salary + "</p>";
// Generate PDF (requires Document Generation / PDF plugin)
var pdf = new sn_pdfgeneratorutils.PDFGenerationAPI();
var pdfDoc = pdf.convertHTMLToPDF(html);
// Attach PDF to record
GlideSysAttachment.insert(sysId, 'u_employee_details',
"Employee_Details.pdf", "application/pdf",
pdfDoc);
}
},
type: 'PDFGeneratorUtils'
};
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @SandeepKSingh ,
----------------------
Please try this Script Include its working on My side
------ I have use the POST which other members have posted !!-----------
var PDFGeneratorUtils = Class.create();
PDFGeneratorUtils.prototype = {
initialize: function() {},
generateEmployeePDF: function(sysId) {
var gr = new GlideRecord('u_employee_details');
if (gr.get(sysId)) {
// Prepare HTML for PDF
var html = "<h2>Employee Record</h2>" +
"<p><b>Name:</b> " + gr.u_employee_name + "</p>" +
"<p><b>ID:</b> " + gr.u_employee_id + "</p>" +
"<p><b>Joining Date:</b> " + gr.u_joining_date + "</p>" +
"<p><b>Salary:</b> " + gr.u_salary + "</p>";
// Generate PDF (requires Document Generation / PDF plugin)
var pdf = new sn_pdfgeneratorutils.PDFGenerationAPI();
var pdfDoc = pdf.convertHTMLToPDF(html);
// Attach PDF to record
GlideSysAttachment.insert(sysId, 'u_employee_details',
"Employee_Details.pdf", "application/pdf",
pdfDoc);
}
},
type: 'PDFGeneratorUtils'
};
If you found my response helpful, I would greatly appreciate it if you could mark it as "Accepted Solution" and "Helpful."
Your support not only benefits the community but also encourages me to continue assisting. Thank you so much!
Thanks and Regards
Ravi Gaurav | ServiceNow MVP 2025,2024 | ServiceNow Practice Lead | Solution Architect
CGI
M.Tech in Data Science & AI
ï”— YouTube: https://www.youtube.com/@learnservicenowwithravi
ï”— LinkedIn: https://www.linkedin.com/in/ravi-gaurav-a67542aa/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @SandeepKSingh ,
For the PDF generation and attachment, you can implement this with an after insert Business Rule on your u_employee_details table.
Here’s an example you can adapt:
Script
(function executeRule(current, previous /*null when async*/) {
if (!current.u_employee_id || !current.u_employee_name) {
gs.warn("Required fields are missing. PDF generation skipped.");
return;
}
// Build HTML content for the PDF
var html = "<html><body>";
html += "<h1>Employee Details</h1>";
html += "<p><b>Employee Number:</b> " + current.u_employee_id + "</p>";
html += "<p><b>Employee Name:</b> " + current.u_employee_name + "</p>";
html += "<p><b>Joining Date:</b> " + current.u_joining_date + "</p>";
html += "<p><b>Salary:</b> " + current.u_salary + "</p>";
html += "</body></html>";
// Use PDF Generation API
var pdfGen = new sn_pdfgeneratorutils.PDFGenerationAPI;
var pdfBlob = pdfGen.convertToPDF(
html, // HTML content
"u_employee_details", // Table name
current.sys_id, // Attach to this record
current.u_employee_id // File name
);
if (pdfBlob) {
gs.info("PDF successfully generated and attached to record: " + current.sys_id);
} else {
gs.error("PDF generation failed for Employee ID: " + current.u_employee_id);
}
})(current, previous);
Key Points:
- This runs after insert, so the PDF is generated right after the record is created.
- The script builds simple HTML (you can extend this with styling or tables if needed).
- PDFGenerationAPI ,takes care of converting HTML → PDF and attaches it to the record automatically.
- Always test this in a sub-prod environment to validate formatting and attachments.
This way, each time a record is created via your Record Producer, the employee details PDF will be automatically generated and attached.
Thanks & Regards,
Muhammad Iftikhar
If my response helped, please mark it as the accepted solution so others can benefit as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Thanks @Ravi Gaurav @Dr Atul G- LNG @Collin Romeijn ... Finally I am abel to do 🙂