Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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 Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

70 views 1 6
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