Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I run a transition's validators before making the transition in code?

Edited

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?

1 answer

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?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

How we use Jira Service Management for our recruitment process! - Part 2

It is never about setting up a process and being done with it. Rather, the focus should always be on optimizing it for the best outcomes. Thus, we didn’t stop at setting up JSM for our recruitment pr...

188 views 0 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you