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

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

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)

3 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.

Hi Josh,

I am doing something very similar. I'm trying to make Epic Link a required fields for all issue types except Epics. Here is what I have

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Level
import org.apache.log4j.Logger


def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)

// Get a reference to the Epic Link Field
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link')
def epicIssue = issue.getCustomFieldValue(epicLink) as Issue
def issueType = issue.getIssueType().getName()
myLog.debug("Issue type is " + issueType)
myLog.debug("Epic link is " + epicIssue)
// If the Epic issue is not an epic, then check if the epic link is set
if(issueType != 'Epic')
{
if(epicLink != null) {
myLog.debug("Epic Link is not set")
}
else {
return true
}
}
else {
return true
}


However, I am returned with the following even when I set the Epic Link field:

2018-08-30 15:53:16,320 DEBUG [jira.groovy]: Issue type is Bug
2018-08-30 15:53:16,320 DEBUG [jira.groovy]: Epic link is JIRA-35
2018-08-30 15:53:16,320 DEBUG [jira.groovy]: Epic Link is not set

 
Any ideas?

Thanks!

Does this script is on scriptrunner console?

I get static type checking: The variable [issue] is undeclared.

Kindly help to get a field value of an epic issue of a particular project.image.png

Awesome, it works! Thank you!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

718 views 7 24
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