I am trying to update a custom field on an issue after a transition. I created a post function with the following code running. It does not throw an error message, when I log it seems to fill the custom field, but in the end nothing happens with the issue.
What am I doing wrong?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueInputParametersImpl;
import java.util.Date.*
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.util.ImportUtils
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def outageStart = customFieldManager.getCustomFieldObject('customfield_12631');
def outageEnd = customFieldManager.getCustomFieldObject('customfield_12632');
def outageDuration = customFieldManager.getCustomFieldObject('customfield_13032');
if(issue.getCustomFieldValue(outageStart) && issue.getCustomFieldValue(outageEnd)) {
def dateValue = issue.getCustomFieldValue(outageStart) as Date
def dateValue2 = issue.getCustomFieldValue(outageEnd) as Date
issue.setCustomFieldValue(outageDuration, ((dateValue2.getTime()-dateValue.getTime())/1000/60))
issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
issueIndexingService.reIndex(issueManager.getIssueObject(issue.id));
ImportUtils.setIndexIssues(wasIndexing);
}