Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,398
Community Members
 
Community Events
165
Community Groups

How to get Epic Link value - Scriptrunner

I have created a listener that fires when an issuelink is created.

I need to get the value from my Source Issue's Epic Link field.

I have to be missing something simple, because I can't get it to work.  My code as it stands is pasted below, and my log just says "epicLink: Epic Link"

Can someone tell me how to get the value of that field instead of what I assume is the field name?

Thanks in advance

---------------------------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue

def linkMgr = ComponentAccessor.issueLinkManager
def cfManager = ComponentAccessor.customFieldManager

def issueLink = event.getIssueLink()
def sourceIssue = issueLink.getSourceObject()
def destinationIssue = issueLink.getDestinationObject()

log.warn ("issueLink: $issueLink")
log.warn ("sourceIssue: $sourceIssue")
log.warn ("destinationIssue: $destinationIssue")


// CHECK TO SEE IF THE SOURCE ISSUE ALREADY HAS AN EPIC LINK
def epicLinkField = cfManager.getCustomFieldObjectsByName("Epic Link") as List
def epicLink = epicLinkField.get(0)


log.warn ("epicLink: $epicLink")

1 answer

1 accepted

0 votes
Answer accepted

I managed to find my own answer.  The issue was that I only had the field itself, but not the value of the field on the issue itself.

the new working code to get the epic link value replaces what is under the comment:

// CHECK TO SEE IF THE SOURCE ISSUE ALREADY HAS AN EPIC LINK

// getCustomFieldObjectsByName() returns a collection.  Appending [0] gets the first item in that collection, and since epic link can only have one value, we know this is correct

def epicLinkField = cfManager.getCustomFieldObjectsByName('Epic Link')[0]

// getCustomFieldValue is a method of Issue and needs a field object like we acquired in the above line

def epicLinkValue = sourceIssue.getCustomFieldValue(epicLinkField)

To anyone looking for things like this - the API documentation is here:
https://docs.atlassian.com/software/jira/docs/api/7.6.1/

It takes a bit to learn how to use if if you're not already familiar with these, but the answers are in there.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PERMISSIONS LEVEL
Site Admin
TAGS

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