Download as PDF from Service Portal

samar sahoo
Tera Contributor

We have a requirement to provide the option for the users to download the content of a portal widget to a downloadable file .pdf. The functionality will be provided through a button available on the portal page. Can you please share ideas if someone has already implemented the above.

1 REPLY 1

Robin John
Kilo Sage

I am assuming that the portal widget will have some dynamic data that is rendered as HTML on the page. 
What you could do is that on the click of this custom button you can extract the rendered HTML in JavaScript <element>.innerHTML

And then you can use the PDF api in ServiceNow to then convert this HTML into PDF.  Some considerations:

1. You will have to use a table and a record in that table to store this attachment

2. Redirect the user to /sys_attachment.do?sys_id=<sys id of the converted attachment>. The attachment will download automatically

3. Delete the attachment after use. This can be done as the api method will return the sys_id of the attachment that is created.

 

For this purpose, you could use a custom table and store the attachment on a record there. And there can then be a scheduled job that deletes all the records and the attachments every 24 hours/at midnight.