I followed the method in this wiki page to show a table in script field: https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/table-custom-field.html
but the table just show text. I also want the issue key in the table is a hyperlink to be clicked.
so I tried to return a html format of hyperlink, it can be displayed as a hyperlink
def hyperlink = "<a href=\""+browseurl+issue.key+"\">"+issue+"</a>";
log.info(hyperlink)
return hyperlink
but when I input this information into a table (as code below), it displays as text.
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${results.total}")
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
def browseurl = com.atlassian.jira.component.ComponentAccessor.getApplicationProperties().getString("jira.baseurl")+"/browse/"
if (results.total < 1)
{
xml.string("Nothing required.")
}
else
{
xml.style(type: "text/css",
'''
#scriptField, #scriptField *{
border: 1px solid black;
}
#scriptField{
border-collapse: collapse;
}
''')
xml.table(id: "scriptField") {
tr {
th("Key")
th("Summary")
th("Status")
}
results.getIssues().each { documentIssue ->
log.debug(documentIssue.key)
// if you need a mutable issue you can do:
def issue_i = issueManager.getIssueObject(documentIssue.id)
// do something to the issue...
log.debug(issue_i.key)
//issue_i hyperlink
def ikey = issue_i.key;
def issue_i_link = "<a href=\""+browseurl+ikey+"\" >"+ikey+"</a>";
tr {
td(issue_i_link)
td(issue_i.summary.toString())
td(issue_i.status.getName())
}
}
}
}
return (writer.toString())
what is displayed:
<a href="https://xxx/xx">issue</a>
You need to either build the URL using the markup syntax or use mkp.yieldUnescaped to have the html interpreted. Read more about the markup builder: http://groovy-lang.org/processing-xml.html#_markupbuilder
xml.table(id: "scriptField") {
tr {
th("Key")
th("Summary")
th("Status")
}
results.getIssues().each { documentIssue ->
def issue_i = issueManager.getIssueObject(documentIssue.id )
def ikey = issue_i.key;
tr {
td{
a(href: "/browse/$ikey") ikey
}
td(issue_i.summary.toString())
td(issue_i.status.getName())
}
}
}
or
td( mkp.yieldUnescaped(issue_i_link) )
BTW, if you want to create a link to jira to be displayed in jira... and you don't have a context path in your environment, you don't need to lookup the base url, you can just use an absolute path starting at root : "/browse/ABC-123" will work. If you have a context path, you can either hard code that or look it up.
Also, with groovy, you can make strings lots easier to read by using triple quoted strings. With those, you don't need to escape quotes:
def longComplexString = """ this string has unescaped "double quotes" """
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.