script field to display parent of sub-task in issue navigator

Hi...I have an script to display the issue key of the parent of a sub-task in issue navigator but I might be missing something since it is not displaying the parent issue key properly. This is the script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

def parentkey = issue.getParentObject().getKey()
def baseUrl = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)

return (issue.parent != null) ? "<a href=\""+ baseUrl + "/browse/"+ parentkey + "<code>" + parentkey + "</code>" + "</a>" : "";


And this is what I am getting (and I want to get KANBAN-15 instead):

<a href="<code>KANBAN-15</code></a>


I definitely need some help in the last line of the script (the return line)...I am getting a yellow warning but I dont understand the format....can you please help with the last line (I know I am missing something there)...thanks

return (issue.parent != null) ? "&lt;a href=\""+ baseUrl + "/browse/"+ parentkey + "&lt;code&gt;" + parentkey + "&lt;/code&gt;" + "&lt;/a&gt;" : "";

1 answer

0 votes

The code you have here is not just for displaying the parent, it's for displaying it as a linkable item, so when it is clicked, you go to the parent.

I am not 100% sure what you really want from your question, but there are two strong possibilities:

1.  When you say you want to see just KANBAN-15, then you don't need all the code for working out the url to link it to.  You can cut the code down to one line:

return issue.getParentObject().getKey()

2.  You do want to show it as a link.  The code you have is fine, but the script field is displaying plain text, so you get it as text.  Go to the script definition and look for the "output template".  Change it from "text" to "html".  That will make JIRA send it to your browser as a link.

Hi Nic...thank you for your answer.

What I want is to display it as a linkable item, so it is option 2. I had set the template to html before asking the question here and it does not do it.




The pic above is the message I am getting when editing the script. It is suggesting a specific format. I think I am missing the closing " or something else. I am not sure about <code> </code> either

Sorry, I skimmed the html as it looked like you had copied and pasted a working script and set the template incorrectly.

You are right about the output being slightly wrong.  You're missing a closing " and yes, you can lose the <code> bit.  i.e.

<a href="<code>KANBAN-15</code></a>

should be

<a href="">KANBAN-15</a>

 I think you need :

"&lt;a href=\""+ baseUrl + "/browse/"+ parentkey + ""&gt;" + parentkey + "&lt;/a&gt;" ;

That should get you closer, but please check it or try it carefully, as I struggle with escaping characters correctly.

Hi Nic....I got the last line of the script as:

return "&lt;a href=\""+ baseUrl + "/browse/"+ parentkey + "\"&gt;"+ parentkey + "&lt;/a&gt;"

but still I am getting the whole string in the Issue Navigator

<a href="">KANBAN-15</a>

Thats the same format as you said, but still it is showing the whole text and not the link.

Thank you for your help.


Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


259 views 0 6
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you