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.
in the HTML Macro we inject:
- The “Print” button
- The function to get the HTML query string and obtain the params
- A function to Print nice the page HTML (without some Confluence headers, footer, etc)
- A function to detect the “Enter” Key and start the process of load the issue/ticket. It calls the “main” function getIssue()
- 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.
- The “main” core function getIssue() that uses a REST call to JIRA to extract all the field information and present in the page.
and we continue processing the fields (it depends of the type of customfield)
For example: The summary field, and Key field it’s easy
A multiple user field it’s more complicated…
Get today date…
Get the reporter….
Get a cascade custom field…
Get date fields.. and “Money” fields…
A Dropdown field… or text field…
And finally, we end the function returning the issue…
- An extra function to format Money fields. (optional)
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
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!
- More info in this post: JIRA Scriptrunner REST Endpoint & Web Fragment example
Here the “button” to print in PDF
Here the web item fragment to show the button
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!