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

Help with script of Transition Linked issues with scriptrunner Edited

Hi!. 

I'm trying to create a script with scriptrunner to be able to tansition two linked issues that, each from different projects. What I want is that when one of these issues goes to "done", the other one does it automatically. 

¿Does anyone have an example of a script i can use?

¿Do i have to select a postfunction or a condition in scriptrunner?

I'm new in groovy and I'm lost!

Thanks!

1 answer

0 votes

"Condition" in workflow only determine if/when a transition button should be available.

PostFunction happens after the transition has been initiated and passed all the validation rules (validators).

So your scenario is a good fit for a post function.

But you indicated that the 2 linked issues are in different projects. That means that they may also have different workflows. That means that you may need to create a post function in both workflows if either of the 2 issues could be marked done first.

You didn't specify your deployment type... so I'll assume "Server". If you are on Cloud, someone else will need to help you as I don't work with Cloud much.

In the workflow Post Functions tab, click "Add post function"

Select "Custom script post-function"

Your script would look something like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.workflow.TransitionOptions

def issueService = ComponentAccessor.issueService
def issueLinkManager = ComponentAccessor.issueLinkManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

//if you have 2 different workflows use the following line
//def actionId = 21 //put the ID of the transition you want to run, that's the number that shows in the workflow text mode for the transition that ends in "Done"

//if the same workflow on all linked issues use this line
def actionId = transientVars["actionId"] as Integer

def links = issueLinkManager.getLinkCollection(issue, currentUser)
links.allIssues.each{linkedIssue->
def transitionOptions = new TransitionOptions.Builder()
//if you want to ignore any condition that would normally hide the transition, uncoment the next line
//transitionOptions =transitionOptions.skipConditions()
//if you want to ignore any validator that could stop the transition, uncoment the next line
//transitionOptions =transitionOptions.skipValidators()
transitionOptions = transitionOptions.build()
def transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue.id, actionId, new IssueInputParametersImpl(), transitionOptions)
if(transitionValidationResult.isValid()){
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
}
}

If you are likely to have other issue links, this might need to be adjusted a little.

Suggest an answer

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

⏰ Day in the life of a Jira Admin!

Hello Community! We thoroughly enjoyed this just-for-fun conversation in the Jira Admin Group about what it's like to be a Jira Admin. For #JiraJuly, our talented designers created these graphics t...

448 views 2 17
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