How to convert issue links into Parent/Child links
Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.
Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
The information on this page relates to custom development via a third-party app in Jira Applications. Consequently, Atlassian Support cannot guarantee the provision of any support for the steps described on this page as custom development and third-party apps are not covered under Atlassian Support Offerings. Please be aware that this material is provided for your information only and that you use it at your own risk.
If you need any help with altering the script or are running into execution issue, we advise to reach out to the Atlassian Community.
As part of the adoption of Advanced Roadmaps, projects that were using issue links to define hierarchy relations will have to use the Parent Link field so they become nicely visible in Advanced Roadmaps plans.
Solution
Execute this Groovy script in the ScriptRunner's development console. Note that the JQL and issue links names will have to be changed accordingly. Follow the code comments for more info.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
// edit this query to suit
def query = jqlQueryParser.parseQuery("project = PORTPC and type =\"Program Epic\" and issueLinkType = \"breakes down into\"")
def searchService = ComponentAccessor.getComponent(SearchService.class)
def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter())
//log.debug("Total issues: ${results.total}")
results.getResults().each {documentIssue ->
log.debug(documentIssue.key)
def issue = issueManager.getIssueObject(documentIssue.id)
// Get issue links
issueLinkManager.getInwardLinks(issue.id).each {issueLink ->
// Edit issue link name here
if (issueLink.issueLinkType.name == "Break Down") {
def linkedIssue = (MutableIssue) issueLink.sourceObject
def parentLinkField = customFieldManager.getCustomFieldObjectByName("Parent Link")
if(linkedIssue.issueType.name == "Epic" && linkedIssue.getCustomFieldValue(parentLinkField) == null)
{
log.warn(issue.key + " is linked to " + linkedIssue.key)
def parentLinkFieldType = parentLinkField.getCustomFieldType()
def newParentLink = parentLinkFieldType.getSingularObjectFromString(issue.key)
linkedIssue.setCustomFieldValue(parentLinkField, newParentLink)
issueManager.updateIssue(user, linkedIssue, EventDispatchOption.ISSUE_UPDATED, false)
}
}
}
}
Was this helpful?