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!
"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:
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)
def transitionOptions = new TransitionOptions.Builder()
//if you want to ignore any condition that would normally hide the transition, uncoment the next line
//if you want to ignore any validator that could stop the transition, uncoment the next line
transitionOptions = transitionOptions.build()
def transitionValidationResult = issueService.validateTransition(currentUser, linkedIssue.id, actionId, new IssueInputParametersImpl(), transitionOptions)
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
If you are likely to have other issue links, this might need to be adjusted a little.
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...
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