How to convert issue links into Parent/Child links

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問


プラットフォームについて: Server と Data Center のみ - この記事は、サーバーおよびデータセンター プラットフォームのアトラシアン製品にのみ適用されます。

   

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. 

ソリューション

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. 

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




最終更新日 2021 年 7 月 16 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.