Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Import issues with epic links and relation links as default links (i.e. relates to).

  2. Allow users to change link types in bulk change via workflow-transition with a scripted post-function. Show this option only to issues that have issue links of defined link type.
    (info) The following scripts allows to define link type per issue type. I.e. you can configure a different target parent link for issues of type “Story” then for issues of type “Epic”.

Workflow Post-function Groovy Script

Code Block
languagegroovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
 
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext()
 
def currentUser = jiraAuthenticationContext.getLoggedInUser()
 
def issueLinkID
def SAJfieldID
 
if (issue.getIssueType().name == "Epic") {
    issueLinkID = 12345 as Long
    SAJfieldID = 11000 as Long
} else if (issue.getIssueType().name == "Story" || issue.getIssueType().name == "Bug" || issue.getIssueType().name == "Task") {
    issueLinkID = 13579 as Long
    SAJfieldID = 11200 as Long
} else {
    return
}
 
def existingLinks = issueLinkManager.getIssueLinks(12345issueLinkID).findAll() { it.sourceId == issue.id } //sourceId, wenn Outward-Link; destinationId, wenn Inward-Link (Vorgang dient als Ausgangspunkt)
def SAJfieldID = 11000 as Long
def SAJfield =  customFieldManager.getCustomFieldObject(SAJfieldID)
 
for (existingLink in existingLinks) {
  	  def destinationIssueId = existingLink.destinationId as Long //destinationId, wenn Outward-Link; sourceId, wenn Inward-Link (Vorgang dient als Ziel des Links)
    	def destinationIssueKey = issueManager.getIssueObject(destinationIssueId).key as String
    log.warn("current: " + issue)
    log.warn("destination: " + destinationIssueKey)
   	 def SAJfieldValue = issue.getCustomFieldValue(SAJfield) as String
  	  if (SAJfieldValue == null) {
        issue.setCustomFieldValue(SAJfield, destinationIssueKey)
    } else if (!SAJfieldValue.contains(destinationIssueKey)) {
        issue.setCustomFieldValue(SAJfield, SAJfieldValue + ", " + destinationIssueKey)
    }
    issueLinkManager.removeIssueLink(existingLink, currentUser)
}
 
issueManager.updateIssue(currentUser, issue, EventDispatchOption.ISSUE_UPDATED, false)

...