I'm trying to conditionally trigger a transition on linked issues as a post function, which is close to working, except that when the linked issue's transition validator fails, the transition that triggered the post function then fails as well, which I don't want. I'd like to skip the linked issue transition in that case, requiring it to be manual. This is what my code looks like:
def transitionValidationResult = issueService.validateTransition(
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),
linkedTicket.getId(),
action.getId(),
new IssueInputParametersImpl()
)
if (!transitionValidationResult.isValid()) {
log.error("'${actionName}' transition is not valid for ${linkedTicket.key}: ${transitionValidationResult.errorCollection}")
return
} else {
log.info("Transitioning...")
}
def transitionResult = issueService.transition(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), transitionValidationResult)
if (!transitionResult.isValid()) {
log.error("Failed to transition ${releaseTicket.key}: ${transitionResult.errorCollection}")
return
}
It seems like the validateTransition() call should return an invalid result, but then the actual transition fails. Am I missing something? Once the actual transition fails, it then automatically rolls back the original transition the user initiated.
UPDATE It's been a few weeks since I asked this - does anyone out there have any ideas?
Seems like a bug in issueService. :-(
I have excactly the same problem. Here is the sample for test from Console:
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor as CA
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.user.ApplicationUser
import org.apache.log4j.Level
import org.apache.log4j.Logger
def ACTION_ID = 131
log.setLevel(Level.INFO)
Issue issue = CA.getIssueManager().getIssueObject("B2-3082")
ApplicationUser user = CA.jiraAuthenticationContext.loggedInUser
IssueInputParameters issueParams = CA.issueService.newIssueInputParameters()
IssueService.TransitionValidationResult validationResult = CA.issueService.validateTransition(user, issue.id, ACTION_ID, issueParams)
log.info "validationResult: ${validationResult.isValid()} errors: ${validationResult.errorCollection.errors}"
if (validationResult.isValid()) {
def transitionResult = CA.issueService.transition(user, validationResult)
if (!transitionResult.isValid()) {
log.warn "Failed to transition issue ${issue.key}, errors: ${transitionResult.errorCollection.getErrorMessages()}"
} else {
log.info "Sussessful transition issue ${issue.key}"
}
} else {
log.warn 'Errors on validation:'
log.warn validationResult.errorCollection.errors
log.warn validationResult.warningCollection.warnings
}
Output:
2021-11-25 10:32:55,554 INFO [runner.ScriptBindingsManager]: validationResult: true errors: [:] 2021-11-25 10:32:55,672 WARN [runner.ScriptBindingsManager]: Failed to transition issue B2-3082, errors: [Comment: Please provide a comment for this transition]
Have you resolved this issue?
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.