Looking to show values from a linked Epic (Script Runner)

Basically all I want is to show an Epic's custom field  value and status on a given feature/linked ticket to that Epic.

 

It'd look like this (two script fields):

Feature --> (Epic's Custom Field)

Feature --> (Epic's Status)

2 answers

1 accepted

Hi Adam,

I wrote two scripts for this. In my first script, attached to a Script Field named "Value of Epic", I get the value of the status from the Epic and display it on the Feature issue. I added an 'if' statement that ensures that this script field only displays on issues that have a type of Feature.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
enableCache = { -> false }
if (issue.getIssueType().name == "Feature") {
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue
if (epicIssue) {
return (epicIssue.status.name)
}
}

My next script, attached to the Script Field "Epic's CF", gets a custom field value from the Epic and displays it. You'll need to change the name of the custom field to match yours.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
enableCache = { -> false }
if (issue.getIssueType().name == "Feature") {
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def epicLinkCf = customFieldManager.getCustomFieldObjectByName("Epic Link")
def epicIssue = issue.getCustomFieldValue(epicLinkCf) as Issue
def epicCustomField = customFieldManager.getCustomFieldObjectByName("TextFieldA") //change to your Epic custom field's name

if (epicIssue) {
return (epicIssue.getCustomFieldValue(epicCustomField))
}
}

Attached image of the result. I tested this on an issue type of Bug, since I don't have an issue type of Feature.

Screen Shot 2017-07-27 at 11.23.02 AM.png 

@Joshua Yamdogo [Adaptavist], how would I make the return searchable if I want to use some JQL like

 

issuetype = X and "Epic's CF" IS NOT EMPTY

 

Right now it doesnt seem to support searching an empty string.

Awesome, it works! Thank you!

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

168 views 0 4
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