I am looking to create a Listener which updates the value of a number type custom field from a scripted calculated number field. We are looking to use this value for reporting and would like it available as a field that can be used in the sprint burndown chart. I tried the following but am getting errors when the listener is triggered.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
def issue = event.issue as Issue
def CurrentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def EpicRiskScore = customFieldManager.getCustomFieldObjectByName("Epic Risk Score Total")
def EpicRiskScoreValue = issue.getCustomFieldValue(EpicRiskScore)
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Risk Score"}
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), EpicRiskScoreValue),changeHolder)
Log Error Below:
Time (on server): Tue Apr 16 2019 14:14:28 GMT-0400 (Eastern Daylight Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2019-04-16 18:14:28,041 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2019-04-16 18:14:28,041 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
at com.atlassian.jira.issue.Issue$getCustomFieldValue$14.call(Unknown Source)
at Script225.run(Script225.groovy:16)
Thanks in advance for any help around this solution 