Jira Software Version: 8.22.6
Adaptavist Script Runner Version: 6.41.0
I'm trying to update the Time Tracking fields on a Story, when the issues and sub-tasks beneath the story submit their work logs. I'm using a listener that fires when a work log is submitted.
I have already checked the variables and verified that the time tracking variables are accurate up to the point of the updateValue() method at the end of this code. The code is compiling and firing without any errors. The listener log says it's running fine.
However, when I add a work logged record to an issue or sub-task, the corresponding Story's Time Tracking fields are not updating at all. I'm adding "Dummy" variables to over-right the Story's current numbers, in order to verify that the code is actually working.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkTypeManager
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import java.text.SimpleDateFormat
Issue issue = event.issue
String issueTypeName = event.issue.getIssueType().name
// Load Components
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def issueManager = ComponentAccessor.getIssueManager()
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def changeHolder = new DefaultIssueChangeHolder()
def actionName = issue.getStatus().name
// Create Variables
def cfOriginalHourEstimate = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Original Hour Estimate'}
def cfRemainingHourEstimate = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Remaining Hour Estimate'}
def cfLoggedHours = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Logged Hours'}
def cfTotalHours = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Total Hours'}
def cfStoryLink = customFieldManager.getCustomFieldObjects(issue).find {it.name == 'Story Link'}
String cvStoryLink = issue.getCustomFieldValue(cfStoryLink)
//ASSIGN DUMMY VARIABLES
def originalHourEstimateDummy = 10 as double
def remainingHourEstimateDummy = 6 as double
def loggedHoursDummy = 4 as double
def totalHoursDummy = 10 as double
// Get Custom Fields
cfOriginalHourEstimate = customFieldManager.getCustomFieldObjectsByName('Original Hour Estimate')[0]
cfRemainingHourEstimate = customFieldManager.getCustomFieldObjectsByName('Remaining Hour Estimate')[0]
cfLoggedHours = customFieldManager.getCustomFieldObjectsByName('Logged Hours')[0]
cfTotalHours = customFieldManager.getCustomFieldObjectsByName('Total Hours')[0]
// These functions ARE running, without errors, but the desired effects aren't happening...
cfOriginalHourEstimate.updateValue(null, remoteIssue, new ModifiedValue(issue.getCustomFieldValue(cfOriginalHourEstimate), originalHourEstimateDummy), changeHolder)
cfRemainingHourEstimate.updateValue(null, remoteIssue, new ModifiedValue(issue.getCustomFieldValue(cfRemainingHourEstimate), remainingHourEstimateDummy), changeHolder)
cfLoggedHours.updateValue(null, remoteIssue, new ModifiedValue(issue.getCustomFieldValue(cfLoggedHours), loggedHoursDummy), changeHolder)
cfTotalHours.updateValue(null, remoteIssue, new ModifiedValue(issue.getCustomFieldValue(cfTotalHours), totalHoursDummy), changeHolder)
// Let's try triggering a re-index once the changes have been uploaded
boolean isIndex = ImportUtils.isIndexIssues()
ImportUtils.setIndexIssues(true)
IssueIndexingService IssueIndexingService = (IssueIndexingService) ComponentAccessor.getComponent(IssueIndexingService.class)
IssueIndexingService.reIndex(issue)