How to get epic tasks in script filed

Katarzyna Kacperska April 16, 2024

I'm using Script Fields in Script Runner.

For an epic I want to display any information from its tasks.
To download these tasks I use the command:

def links = issueLinkManager.getOutwardLinks(issue.id)


but this returns me not only issues in epic but also other issues linked to it.

How to get only issues which are connected via thic Epic by epic link ?

2 answers

1 accepted

0 votes
Answer accepted
Ram Kumar Aravindakshan _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 16, 2024

Hi @Katarzyna Kacperska

The approach you are trying alone will not work.

You need to perform other steps for the filtration to work correctly.

Below is a sample working code for your reference:-

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager

if (issue.issueType.name == 'Epic') {
def listOfTasks = issueLinkManager.getOutwardLinks(issue.id).collect { issueLink ->
if (issueLink.destinationObject.issueType.name == 'Task') {
issueLink.destinationObject
}
}.findAll {it != null}

listOfTasks
} else {
return
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a screenshot of the Scripted Field configuration:-

scripted_field_config.png

Below is a test output:-

If you observe the screenshot below, as configured in the Scripted Field code, it will only display all Task issue types that belong to the epic.

test.png

 

I hope this helps to solve your question. :-)

Thank you and Kind regards,
Ram

Ram Kumar Aravindakshan _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 17, 2024

Hi @Katarzyna Kacperska

Great to hear the solution worked for you. :-)
Please accept the answer provided.


Thank you and Kind regards,
Ram

0 votes
Katarzyna Kacperska April 17, 2024

Hi Ram,

Thank you very much for your answer. I used this commands:

def links = issueLinkManager.getOutwardLinks(issue.id)
links.each { issueLink ->
       
        if (issueLink.issueLinkType.name == "Epic-Story Link") {  
...

but the solution you provided is better.

Regards,

Kate

Suggest an answer

Log in or Sign up to answer