In this example, we will create a Confluence page and we will use it as “Template” to print documents (in this case issue tickets) in PDF or directly to the printer.

Based on this exercise:  How to show Jira ticket fields in Confluence pages

As prerequisites we need:

  • Jira Server
  • Confluence Server
  • Optional: Atlassian Crowd to allow SSO and make the experience transparent to the user.

First we create a page in Confluence, and we will use the “HTML Macro” for each data to display also to inject the javascript libraries.

Captura de pantalla 2018-07-16 a las 16.19.54

in the HTML Macro we inject:

  • The “Print” button

Captura de pantalla 2018-07-16 a las 16.21.37

  • The function to get the HTML query string and obtain the params

Captura de pantalla 2018-07-16 a las 16.23.22

  • A function to Print nice the page HTML (without some Confluence headers, footer, etc)

Captura de pantalla 2018-07-16 a las 16.24.12

  • A function to detect the “Enter” Key and start the process of load the issue/ticket. It calls the “main” function getIssue()

Captura de pantalla 2018-07-16 a las 16.26.05

  • A function to execute getIssue() (the main function) once the page is loaded (to automatize the report using a Jira method/fragment trigger). Also the “Print” action ca be automatized.

Captura de pantalla 2018-07-16 a las 16.28.12

  • The “main” core function getIssue() that uses a REST call to JIRA to extract all the field information and present in the page.

Captura de pantalla 2018-07-16 a las 16.33.29

and we continue processing the fields (it depends of the type of customfield)

For example: The summary field, and Key field it’s easy

Captura de pantalla 2018-07-16 a las 16.34.36

A multiple user field it’s more complicated…

Captura de pantalla 2018-07-16 a las 16.35.22

Get today date…

Captura de pantalla 2018-07-16 a las 16.36.19

Get the reporter….

Captura de pantalla 2018-07-16 a las 16.37.11

Get a cascade custom field…

Captura de pantalla 2018-07-16 a las 16.37.46

Get date fields.. and “Money” fields…

Captura de pantalla 2018-07-16 a las 16.39.24

A Dropdown field… or text field…

Captura de pantalla 2018-07-16 a las 16.41.26

And finally, we end the function returning the issue…

Captura de pantalla 2018-07-16 a las 16.42.03

  • An extra function to format Money fields. (optional)

Captura de pantalla 2018-07-16 a las 16.31.28

Now we have the HTML completed!

Then we only need to add new HTML Macros in each part of the document to fill the fields info and get ready the page for Printing

Captura de pantalla 2018-07-16 a las 16.44.04

To finish the new “Printing” functionality, you can add with ScriptRunner or with a custom plugin a new “fragment” (option) to the Issue View to let users print from the ticket!

Here the “button” to print in PDF

Captura de pantalla 2018-07-16 a las 16.46.59

Here the web item fragment to show the button

Captura de pantalla 2018-07-16 a las 16.48.44

By MrAddon

In the next post we will try to do the same, but exporting to WORD!

BTW in MrAddon we have a plugin to print beautiful cards from your Agile board Jira tickets! Try it for free!

Try Issue Card Printer for JIRA

Try Issue Card Printer for JIRA Cloud

mr.addon-33

 

Posted by:.

One thought on “How to print custom PDF templates of Jira tickets using Confluence

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s