How to display an issue key as a link in a scripted field

jira-admins November 28, 2018

Looking at the example given here https://scriptrunner.adaptavist.com/latest/jira/recipes/misc/table-custom-field.html

This is exactly what I need, but I would love if instead of listing the issuekeys I could list html links to these issues.

In the example the table is made up by adding keys like this:

# td(issue.key.toString())

resulting in something like this

# <td>TEST-4</td>

I would like to have as the result 

# <td><a href="https://.../TEST-4>TEST-4</a></td>

But

td("<a href=\"https://../browse/${issue.key.toString()}\">${issue.key.toString()}</a>")

does not help..

 

Any suggestions?

1 answer

1 accepted

0 votes
Answer accepted
Nir Haimov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 28, 2018

Hi,

Change the scripted field template type from "HTML" to "Text Field (multi-line)"

Copy this exactly to your scripted field and it will work for you.

import com.atlassian.jira.component.ComponentAccessor

def baseurl = ComponentAccessor.getApplicationProperties().getString("jira.baseurl");

"<td><a href='${baseurl}/browse/${issue}'>${issue}</a></td>"

 In order to show in a table just add some html as string to the scripted field

jira-admins November 28, 2018

Thanks Nir,

I am new to this scripting language, but your answer helped me find the solution.

The final result in my script looks like this (and it seems to work fine):

def mystring = "<html>\n" +
"<head>\n" +
"<style>\n" +
"table, th, td {\n" +
" border: 1px solid black;\n" +
" border-collapse: collapse;\n" +
"}\n" +
"th, td {\n" +
" padding: 5px;\n" +
" text-align: left; \n" +
"}\n" +
"</style>\n" +
"</head>\n" +
"<body>\n" +
"\n" +
"<table>\n" +
" <tr>\n"+
" <th>Issue Key</th>\n" +
" <th>Summary</th>\n" +
" <th>Status</th>\n" +
" </tr>\n"

results.getIssues().each {documentIssue ->
def issue = issueManager.getIssueObject(documentIssue.id)
mystring += " <tr>\n"
mystring += " <td><a href='${baseurl}/browse/${issue.key}'>${issue.key}</a></td>\n"
mystring += " <td>${issue.summary}</td>\n"
mystring += " <td>${issue.status.getName()}</td>\n"
mystring += " </tr>\n"
}

mystring += "</table>\n</body>\n</html>"

return mystring

For reference the code I had (based upon an example) looked like this:

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 ->
def issue = issueManager.getIssueObject(documentIssue.id)
tr{
td(issue.key.toString())
td(issue.summary.toString())
td(issue.status.getName().toString())
}
}
}

return (writer.toString())
Like Nir Haimov likes this
jamila.augustine February 24, 2020

Hello @Nir Haimov : Do you know if I can use a similar script to create a field to display a filter as a link? What I really want is to display specific filters as link on my dashboard. (Similar to what fav filter gadget already does: except that this is not all my fav filter)..

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events