Hi,
I am trying to write a Groovy script to update the field Epic Link with a default value if the Epic Link was not set.
After searching the web and reading some articles, I found this code, which I have modified to only do the update if the current value if null:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def epicIssue = issueManager.getIssueObject("JIRAMTCE-10") // Epic issue key here
def epicLink = customFieldManager.getCustomFieldObjectByName("Epic Link")
if (issue.getCustomFieldValue(epicLink) == null) {
log.info("Setting the Epic Link to JIRAMTCE-10")
issue.setCustomFieldValue(epicLink,epicIssue)
} else {
log.info("Epic Link was not null")
}
I also added the issue.setCustomFieldValue line as the original line gave an error.
FYI: Here is the original line that I replaced with the issue.setCustomFieldValue:
epicLink.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(epicLink), epicIssue),new DefaultIssueChangeHolder())
The code is placed as a Post Function to the workflow transition.
Finally I would like to say that this is my first attempt at Groovy so I imagine that the mistake is a very basic error because of my inexperience.
Any advice you can give will help me learn.