- 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
Hi @harshaa0567 - there are a number of ways to accomplish this using the PDF Generation API in ServiceNow. However, if you need a turn-key solution with more flexibility, Yansa Labs offers a certified ServiceNow Store app that makes it easy to create a custom, well-formatted PDF accessible via click-of-a-button on the form. If it's useful, it's free to trial at the link below. Feel free to reach out to me directly if we can help!
- 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
2 weeks ago
Can you help me on how to make the button to work on workspace. I'm working on custom application , custom workspace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
in your original question you didn't mention about workspace
But if you still require then the above code will work fine in workspace as well as it's server side
Just ensure these 2 checkboxes are true and it work fine in workspace as well
💡 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
2 weeks ago
Yes I had make one Ui Action and also check the workspace checkbox but on workspace when I click that ui action i.e Download PDF there this page is opening not directly downloading the pdf..??