You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Auto Link and Issue to an Epic

Overview

A Post-Function to automatically link an issue type (for example a Story) to a specific Epic when the issue is being created. This will take effect only if the Epic Link field in that issue is left blank.

Example

In the sample code below, an issue type is automatically linked to an Epic if the Epic Link is not added when the issue is being created.

Requirements

  • Jira Jira (8.0 - 8.18)
  • ScriptRunner for Jira ScriptRunner for Jira (6.32.0)
    
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption def customFieldManager = ComponentAccessor.customFieldManager def issueManager = ComponentAccessor.issueManager def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser //This requires name of the Issue Type that is to be linked to the Epic final def issueTypeName = '' //This requires key of the Epic that will be linked the issues final def epicIssueKey = '' def epic = issueManager.getIssueByCurrentKey(epicIssueKey) def epicLinkCustomField = customFieldManager.getCustomFieldObjects(issue).findByName('Epic Link') if (issue.issueType.name != issueTypeName) { return } if (!epicLinkCustomField.getValue(issue)) { issue.setCustomFieldValue(epicLinkCustomField, epic) issueManager.updateIssue(loggedInUser, issue, EventDispatchOption.ISSUE_UPDATED, false) }
Discovered an issue? Report it here

Suggested for you