- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi,
I have a requirement to create a UI button on the form that Should export only a particular section on the form. For example in incident form I want to export only "resolution notes" section as PDF.
Can anyone please provide me the solution for it.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
var pdf = new sn_pdfgeneratorutils.PDFGenerationAPI();
var html;
var gr = new GlideRecord("incident");
if (gr.get(current.sys_id)) {
html = "<html><body>";
html += "<h2>Resolution Notes</h2>";
html += "<p><b>Incident:</b> " + gr.number + "</p>";
html += "<p><b>Short Description:</b> " + gr.short_description + "</p>";
html += "<hr>";
html += "<p>" + (gr.close_notes || "No resolution notes available.") + "</p>";
html += "</body></html>";
var result = pdf.convertToPDF(html, 'incident', current.sys_id, "Incident Pdf");
if (result.status ==='success' && result.attachment_id) {
var downloadURL = '/sys_attachment.do?sys_id=' + result.attachment_id;
var gURL = new GlideURL(downloadURL);
action.setRedirectURL(gURL);
//action.setReturnURL(url);
gs.addInfoMessage("PDF generated successfully.");
} else {
gs.addErrorMessage("PDF generation failed.");
}
}
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for.
Thank You
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @harshaa0567,
You would need to make a scripted UI action, then format the html to include the needed fields. Here is a post with a rough example of the code. Here is also another post on how to work with PDFGenerationAPI.
I hope this helps!
Sr. ServiceNow Developer | Infosys
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
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
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hello @harshaa0567 ,
Refer this code snippet,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hello @harshaa0567 ,
If above solution helps you then mark it as helpful and accept as solution.
Regards,
Aditya