PDf generation with HTML template With Loop funtionality

Kachu
Mega Sage

HI Community, I have requirement for one of the FRA report Form 55A which you can find online at https://data.transportation.gov/Railroads/Injury-Illness-Summary-Casualty-Data-Form-55a-/rash-pd2d/a...

Now. I have incident and have 5 injury records. the 55a form that is present has 3 same sections starting from  5A -5U. Each injury record is for individual who is injured not if its more than 3 it needs to append  same form again  as sheet 2 and add  record 4 and 5 information respectively. How can we  achieve this?

 We can generate one document through document template if we have editable PDF but checking the records and appending if there are more to same document and could have more than 30 injury records then shoul have 30 pages for this in one document. this is FRA reportable and need to be done.

Let me knwo if any one have any idea on how can we achieve this.
thanks

6 REPLIES 6

Florisvmuijen
Tera Contributor

Hi Kachu,

 

This is difficult to achieve using the standard ServiceNow Document Template functionality.

Document Templates can generate a document from a record, but they do not handle dynamic repeating sections very well. In your case the injury section (5A–5U) would need to repeat for each related injury record and create additional pages when needed.

 

To achieve this you would typically need either a custom solution that generates and merges multiple pages, or use a document generation application from the ServiceNow Store that supports repeating sections and multi-page output.

 

Hope this helps.

I was able to achieve this using document templates html template and script inlcude, Document template script. only thing is remained is the Html allingement.

Nice solution using an HTML template and script include.

 

We’ve seen this requirement quite often in larger ServiceNow implementations. Standard Document Templates can work well for simple scenarios, but once you introduce repeating sections (for example related records) or multi-page output it usually requires custom scripting to iterate through the data and render the sections dynamically.

 

Your approach using a Script Include and Document Template script is a common way to achieve this. Essentially you generate the HTML structure yourself and loop through the related records to build the repeating sections.

 

The main challenges usually appear around pagination, layout stability and long-term maintainability of the HTML templates when documents become larger or additional sections are added later.

 

In those situations many teams eventually move to a dedicated document generation solution that supports repeating sections and multi-page documents out of the box instead of maintaining custom scripting.

 

But nice workaround and thanks for sharing the approach!

Ankur Bawiskar
Tera Patron

@Kachu 

not possible with Document template with fillable PDF since it has limitations

you can use PDF Generation API

Generating Custom PDFs - using the new PDFGenerationAPI

💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 10x ServiceNow MVP  ||  ✨ ServiceNow Community Leader