John Miller
John Miller

Reputation: 513

How to set epic link in Jira using Groovy

I need to set epic link using groovy if a condition is true. I'm using the following script:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
def epiclink = CustomFieldManager.getCustomFieldObject("customfield_10101") 
issue.setCustomFieldValue(epiclink,"TS-14")

If I set the epic link to null it works,

    issue.setCustomFieldValue(epiclink, null)

but setting it to an issue key doesn't work.

Any help is appreciated.

Upvotes: 0

Views: 1647

Answers (1)

ZeddZull
ZeddZull

Reputation: 288

I'm not sure why you aren't using ComponentAccessor.getIssueManager(), but that is a different question.

Epic Link is an Issue Object, not the Key

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.Issue;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueManager issueManager = ComponentAccessor.getOSGiComponentInstanceOfType(IssueManager.class)
def epiclink = CustomFieldManager.getCustomFieldObject("customfield_10101") 

issue.setCustomFieldValue(epiclink,IssueManager.getIssueObject("TS-14"))

Upvotes: 1

Related Questions