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

Manjunatha K R March 6, 2017

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

1 vote
Manjunatha K R March 21, 2017

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)            
        }    
    }
 }
}
0 votes
QuentinB
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.
March 6, 2017

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

Manjunatha K R March 6, 2017

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)

Manjunatha K R March 7, 2017

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

adammarkham
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.
April 4, 2017

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