How to generate a custom PDF?

Community Alums
Not applicable

Hi,

I need to have a button on incident. 

When the button is clicked, a PDF must be generated. That PDF must contain details of assigned_to user and some custom text which client has suggested. 

Help me in understanding as to how can I achieve this.

1 ACCEPTED SOLUTION

Hi,


Use this share utility:

https://developer.servicenow.com/app.do#!/share/contents/3429377_pdf_generator?v=1.02&t=PRODUCT_DETAILS

 

Thanks,
Ashutosh

View solution in original post

13 REPLIES 13

1. Well the library is on the client side so you can import it just as any third party library, from CDN maybe or you can even host it on the platform.

 

2. yeah so the library I use (pdfmake) you basically build the pdf yourself, so I just pass the data in a UI page query the database with gliderecord and pass it to the client side just in a javascript variable, then the client side generates the pdf. it's not sending a html page into it but rather directly data style information is also in the variable.

 

3. as for how to open a new window or call your UI page, I think you can set just a browser redirect in your UI action to point to your UI page.
But I did invoke a glidedialogwindow which calls my UI page and opens it in a dialog window.

I guess an example would be,

 

server side:

<jelly script tag>

gr = new GlideRecord("incident");

var parcel =[];

while (gr.next()){

  parcel.append(gr.getstuff());

}

parcel.append(addsomeotherstuff());

parcel.stringify();

<jelly script tag/> 

client side:

 <script src="somecdn.com/pdfmake" />

<script>

var content = JSON.parse (${parcel}).customParseFunction()

 

pdfmake.createPDF(content).open()

</script>

 

M_rio Rui Castr
Kilo Expert

Hey,

We have developed a solution that allows you to generate DOCX, PPTX and XLSX files directly from ServiceNow, based on user templates. You can choose what data you want to export so you don't get a file cramped with data.

After exporting you can always edit your files and save them as PDF if needed.

If you are curious about it, we have an article with some more information:

https://community.servicenow.com/community?id=community_article&sys_id=35679790db1bcc90414eeeb5ca961...

I cannot access this Link