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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

How to get Epic Link value - Scriptrunner

padraik
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2022

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")

2 answers

1 accepted

0 votes
Answer accepted
padraik
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2022

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)

padraik
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2022

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.

0 votes
padraik
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 05, 2023

This can't be for cloud, right?  I can't do any of those imports

Suggest an answer

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

Atlassian Community Events