how to get list of associated issues (i,e Issues in Epic) for an EPIC Issue Type using Groovy script?

Hi,

can some one help on how to get list of associated issues (i,e Issues in Epic) for an EPIC Issue Type using a groovy script?

From the associated issues list, I would like to check issue type of the "associated issues" using groovy script and need to update the specific custom field value, when a specific issue type =  CIL in my post function.

Is the below code snippet can be used to get the "Issue in Epic", but I am not sure what is the value should be used for "<Name of Link>" for "Issues in Epic" unlike Blocks/Cloners, etc as it will not be defined as part of the "Issue linking". Please advice.

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
  
def greatestDate;
issueLinkManager.getOutwardLinks(issue.id).each {issueLink ->
    if (issueLink.issueLinkType.name == "<Name of Link>") {
        def linkedIssue = issueLink.destinationObject
         
    }
}

Please suggest how to get this in groovy script.

  • Manju

2 answers

All,

Please find the working script to get the list of associated issues (i,e Issues in Epic) for a EPIC issue Type.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
MutableIssue epicLink = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Epic Link")) as MutableIssue;

final Collection&lt;Issue&gt; issuesInEpic = new ArrayList&lt;Issue&gt;();
if(epicLink.issueType.name=="Epic") {
issueLinkManager.getOutwardLinks(epicLink.id).each {issueLink -&gt;
    if (issueLink.issueLinkType.name == "Epic-Story Link") { 
        Issue linkedIssue = issueLink.destinationObject
        //you can validate if any other specific issue type check is required
        if(linkedIssue.issueType.name == "Development Ready for Check-in"){
            issuesInEpic.add(linkedIssue)
            log.info(linkedIssue)            
        }    
    }
 }
}

Hello, maybe this discussion can help you :
https://answers.atlassian.com/questions/15699065
Regards 

Thanks Quentin for the related link shared.

Using getIssuesInEpic() function shared in the related Atlassian links, was trying to copy EPIC's one of the custom field value i,e "SDD Doc Version Committed in Sprint" to custom field (i,e SDD Doc Version Committed in CIL Sprint) value of associated issues (i,e Issues in Epic) of Issue Type = CIL using the below groovy script.

I am not getting what is the correct way of using Issue = getIssuesInEpic(epicLink) API.

Please advice on how to use  getIssuesInEpic to get all the associated issues and check their respective issueType to perform setCustomFieldValue() based on my above requirement shared in my post function.

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor

MutableIssue epicLink = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Epic Link")) as MutableIssue;
Issue = getIssuesInEpic(epicLink)

if(Issue.issueType.name=="CIL") {

def SprintversionUpdated = epicLink.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("SDD Doc Version Committed in Sprint"));

CustomField Versions = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("SDD Doc Version Committed in CIL Sprint");

Issue.setCustomFieldValue(Versions,SprintversionUpdated)

}

I was referring to the below EpicLinkManager's getIssuesInEpic shared in our Atlassian answers to get my script done...

Probably I need to use the EpicLinkManager's getIssuesInEpic https://docs.atlassian.com/greenhopper/6.3.9.2/com/atlassian/greenhopper/manager/issuelink/EpicLinkManager.html#getIssuesInEpic(com.atlassian.jira.issue.Issue)

@Adam Markham [Adaptavist]

I am trying to add you in this answer chain as we have done similar script to set the ITG-IN due date value of an EPIC into associated issues ITG-IN due date long back.

Apologies that I didn't get round to answering this. It sounds like you have a working script now. I've upvoted your answer too.

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 Monday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

685 views 6 13
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