Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

Web fragment for rendering a pdf with the result of a jql


The following is the code I am trying to implement in the Rest Endpoint for creating a Web fragment for rendering a pdf with the result of a jql

This code does not work and it is complaining about the Permissions library and some of the static methods (which usually only complains but allows you to create the script, not in this case)


import groovy.transform.BaseScript


import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.UserProjectHistoryManager
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.util.velocity.VelocityRequestContextFactory
import com.atlassian.jira.web.bean.*
import com.atlassian.plugin.web.api.model.WebFragmentBuilder

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import org.springframework.util.FileCopyUtils

@BaseScript CustomEndpointDelegate delegate

//identify the last project accessed by the User 
def lastProjectAccessed = ComponentAccessor.getComponent(UserProjectHistoryManager.class)
def projectAcessed = lastProjectAccessed.getCurrentProject(Permissions.BROWSE, ComponentAccessor.jiraAuthenticationContext.loggedInUser)
def projectName =

// PDF configuration
def userName = "admin" // this user runs the search and generates the PDF
def jql = "XXXX"

def templateName = "issue-navigator-fo.vm"
def title = "XXXX"

// run the search
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def query = jqlQueryParser.parseQuery(jql)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.userUtil.getUser(userName)
def results =, user, PagerFilter.getUnlimitedFilter())

// render the PDF
def issues = results.issues
if (issues) {
def pdfApiClass = this.class.forName('com.midori.jira.plugin.pdfview.api.PdfApi', true, ComponentAccessor.pluginAccessor.classLoader)
def pdfApi = ComponentAccessor.getOSGiComponentInstanceOfType(pdfApiClass)
def pdfResult = pdfApi.getPdf(templateName, title.toString(), issues, [:])

// write the pdf to a file with a timestamped filename like "example-20170526-1304.pdf")
FileCopyUtils.copy(pdfResult.bytes, new File("c:\\tmp\\example-${new Date().format('yyyyMMdd-HHmm')}.pdf"))

def searchService = ComponentAccessor.getComponent(SearchService)
def jiraAuthenticationContext = ComponentAccessor.getComponent(JiraAuthenticationContext)

def velocityRequestContextFactory = ComponentAccessor.getComponent(VelocityRequestContextFactory)
def requestContext = velocityRequestContextFactory.getJiraVelocityRequestContext()
def baseUrl = requestContext.getBaseUrl()

results.issues.collect { issue ->
def issueLabel = "${issue.key} ${issue.summary}"

String iconUrl = issue.issueTypeObject.iconUrl
if (!iconUrl.startsWith("http://") && !iconUrl.startsWith("https://")) {
iconUrl = baseUrl + iconUrl;
new WebFragmentBuilder(50).
addParam("class", "issue-link").
addParam("data-issue-key", issue.getKey()).
addParam("iconUrl", iconUrl).
url(baseUrl + "/browse/" + issue.getKey()).


0 answers

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Service Management

Improving the Create Issue Experience in Jira Service Management Cloud

Hello everyone!  We are very excited to announce some much needed changes to the issue create experience in JSM (the blue "create" button) at the top of the screen.  We have just starte...

264 views 13 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you