Skip to main content
Example scripts
arrow icon
To homepage
Jira Software
Data centre icon
Data Center

Update the Epic Link for an Issue in Jira

Created 1 year ago, Updated 1 day(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira Software (7.7 - 8.6)
compatibility bullet
ScriptRunner For Jira (5.6.14)
Language |
groovy
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

// the issue key of the issue that will be added to an epic
final String issueKey = "JRA-1"

// the issue key of the epic issue
final String epicIssueKey = "JRA-2"

// the name of the custom field to update (in our case is the Epic Link)
final String epicLinkFieldName = "Epic Link"

def issueManager = ComponentAccessor.issueManager
def issue = issueManager.getIssueByCurrentKey(issueKey)
def epic = issueManager.getIssueByCurrentKey(epicIssueKey)

def targetField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(epicLinkFieldName)
assert targetField : "Could not find custom field with name $epicLinkFieldName"

targetField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(targetField), epic), new DefaultIssueChangeHolder())
Having an issue with this script?
Report it here