Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Transition issue upon issue update with JMWE/Scriptrunner

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?

1 answer

1 accepted

1 vote
Answer accepted

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 @Peter-Dave 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

Like Peter-Dave Sheehan likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

ThinkTilt is joining the Atlassian Family!

This morning, Atlassian announced the acquisition of ThinkTilt , the maker of ProForma, a no-code/low code form builder with 700+ customers worldwide. ThinkTilt helps IT empower any team in their or...

222 views 14 14
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