Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

html created in widget to export as pdf and download

cnough
Tera Contributor

Is it possible to export custom html created in widget to pdf then download?

2 ACCEPTED SOLUTIONS

AnirudhKumar
Mega Sage

Hello @cnough ,

 

I do not understand the use case, but it's pretty simple to create a pdf if you have the data and a record to attach it to.

See the below script:

var html = '';

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var gr = new GlideRecord("kb_knowledge"); //attaching to a kb record for demo purpose
if (gr.get('c85cd2519f77230088aebde8132e70c2')) { //this is a kb record sysid, the attachment will attach here
 html = gr.text.toString();
} 

var result = v.convertToPDF(html, "kb_knowledge", "c85cd2519f77230088aebde8132e70c2", "myPDF");

View solution in original post

Ravinder Shanka
Tera Expert

Hi AnirudhKumar

 

The above code fetches the content from the kb_knowledge table and then exports, its similar to how export works from form. But is there a way just click a button on the portal and the contents of the widget exports to a PDF with the color styling etc? I want this to export the knowledge article from Portal. 

View solution in original post

2 REPLIES 2

AnirudhKumar
Mega Sage

Hello @cnough ,

 

I do not understand the use case, but it's pretty simple to create a pdf if you have the data and a record to attach it to.

See the below script:

var html = '';

var v = new sn_pdfgeneratorutils.PDFGenerationAPI;
var gr = new GlideRecord("kb_knowledge"); //attaching to a kb record for demo purpose
if (gr.get('c85cd2519f77230088aebde8132e70c2')) { //this is a kb record sysid, the attachment will attach here
 html = gr.text.toString();
} 

var result = v.convertToPDF(html, "kb_knowledge", "c85cd2519f77230088aebde8132e70c2", "myPDF");

Ravinder Shanka
Tera Expert

Hi AnirudhKumar

 

The above code fetches the content from the kb_knowledge table and then exports, its similar to how export works from form. But is there a way just click a button on the portal and the contents of the widget exports to a PDF with the color styling etc? I want this to export the knowledge article from Portal.