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

Tomas Arguinzones Yahoo April 10, 2017

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.config.properties.APKeys
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="https://sbjira.dtveng.net/browse/KANBAN-15<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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2017

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.

Tomas Arguinzones Yahoo April 10, 2017

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.

 

parent.png

 

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 10, 2017

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="https://sbjira.dtveng.net/browse/KANBAN-15<code>KANBAN-15</code></a>

should be


<a href="https://sbjira.dtveng.net/browse/KANBAN-15">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.
 



Tomas Arguinzones Yahoo April 10, 2017

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="https://sbjira.dtveng.net/browse/KANBAN-15">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
TAGS
AUG Leaders

Atlassian Community Events