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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

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

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

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

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

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
Community showcase
Published in Marketplace Apps & Integrations

Bitbucket Smart Commits vs. Genius Commits - What's the difference?

If you already heard about Smart Commits in Bitbucket, know that you just stumbled upon something even better (and smarter!): Genius Commits by Better DevOps Automation for Jira Data Center (+ Server...

106 views 0 2
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