In a project we have an Initiative issue that contains project information like financial code and such. I would like to have a script run that when any epic is created the value of this custom field financial code be prepopulated in these epic. I ma a beginner user with scriptrunner and have ni idea where to start.
Following code is what I came up with
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issue as MutableIssue
["Initiative"].each { cfname ->
def cf = customFieldManager.getCustomFieldObjects(issue).find {it.name == cfname}
log.error("cf : " + cf)
log.error("issue : " + issue)
def epicCf = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Epic Link'}
if (!cf || !epicCf) {return}
def epic = issue.getCustomFieldValue(epicCf) as Issue
if (!epic) {return}
def cfValue = cf.getValue(epic)
log.error("cfValue : " + cfValue)
issue.setCustomFieldValue(cf, cfValue)
}