One of the users in our Jira instance requested an automation process, where an issue auto-transitions from the status Done to the status With Team if a user in the "Customer" role posts a comment on the ticket that's listed as Done.
I know this would be easily doable through Code Barrel's Automation for Jira add-on, but given that our Data Center instance doesn't have this, I was wondering if this was possible with either JMWE or Scriptrunner?
Yes that's possible with scriptrunner.
But dealing with workflows and transition is one of the slighly more involved/complex scripts.
You'll want to use a custom scripted listener with the Issue Commented event
It will look something like this:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.workflow.TransitionOptions
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.security.roles.ProjectRoleManager
def issueService = ComponentAccessor.issueService
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def custRole = projectRoleManager.getProjectRole('Customer')
Issue issue = event.issue
if(projectRoleManager.isUserInProjectRole(currentUser, custRole, issue.projectObject)){
def transitionOptions = new TransitionOptions.Builder()
transitionOptions.skipConditions() //remove this if you want the conditions to be evaluated against the current user
transitionOptions.skipValidators() //remove this if you want your validators to fire and possibly prevent the completion
def inputParams = new IssueInputParametersImpl()
/* use inputParams to set any values that must be set during the transition if you don't have other defaults in the workflow
inputParams.addCustomFieldValue('customfield_123456', 'string value')
*/
def actionId = 123 //this is the id of the transition you want to execute
def transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId, inputParams, transitionOptions.build())
if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
if(transitionResult.isValid()){
log.debug "The transition was succesful"
} else {
log.error "The transition failed: ${transitionResult.getErrorCollection()*.errorMessages}"
}
} else {
log.error "The transition failed the validation: ${transitionValidationResult.getErrorCollection()*.errorMessages}"
}
}
If you need to examine the content of the comment to decide whether or not to trigger the transition, you'll want to look into event.comment.body
Many thanks @PD Sheehan !
The listener script works like a breeze. All I did to change this up a bit was adding a couple other conditions to line 15 to make sure that the status is initially 'Done' and that the issue type is 'Support Request' to completely fulfill our specific use case.
Thank you once again for providing your insight like you have done so before in the past :)
-Ian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.