Hey community,
i am trying to auto-transition an issue using a script listener depending on a linked issue but there is an error i don't really understand:
t seems that you have tried to perform a workflow operation (Done) that is not valid for the current state of this issue (FOSS-15). The likely cause is that somebody has changed the issue recently, please look at the issue history for details.
Although the issue history is empty at this time.
When I run the same code on the same issue in the script console, the transition works. Do you guys have any clue what possibly have gone wrong?
This is my code:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.user.ApplicationUser
// only transition tasks
if (issue.issueType.name != "Task") {
log.warn("This is not a task!")
return
}
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def cfield = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10108")
def linkedIssue = issue.getCustomFieldValue(cfield)
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def actionId = 0
switch (linkedIssue.status.name) {
case "Done":
actionId = 31
break
case "In Progress":
actionId = 21
}
log.error(issue.status)
def issueInputParameters = issueService.newIssueInputParameters()
def validationResult = issueService.validateTransition(user, issue.id, actionId, issueInputParameters)
if (!validationResult.isValid()) {
log.error("invalid transition: ${actionId}")
log.error(validationResult.errorCollection)
log.error(validationResult.warningCollection)
return
}
def transitionResult = issueService.transition(user, validationResult)
if (!transitionResult.isValid()) {
log.error("failed transition")
return
}