Script Runner Transition parent issue based on linkedissues

Karl Samson September 30, 2021

We are trying to get a Feature to automatically transition to 'In Progress', when one or all of the linked issues are also transitioned.

1 answer

0 votes
Winnie _Adaptavist_ October 3, 2021

Hi Karl, 

Assuming that the Feature should transition into In Progress status when the linked issue transitions from [To Do - In Progress], you may set up a Custom script post-function at this transition step.

There's a sample script in the Adaptavist Library that you may adapt to your use case: Transition an Issue using Issue Input Parameters

I modified it to fit your requirements, maybe not exactly but you may try this out. Also, I'm unsure if your issue can have multiple Features linked to/from it. However, this script takes that into consideration. 

You can test this script in the Script Console & change it up as needed:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def workflowManager = ComponentAccessor.workflowManager
def issueService = ComponentAccessor.issueService
def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

// test issue - remove the following line when implementing post-function script
//def issue = ComponentAccessor.issueManager.getIssueObject('TEST-1')

// the name of action used to transition Feature(s)
final actionName = 'In Progress'

// the corresponding workflow id
def actionId = workflowManager.getWorkflow(issue).allActions.findByName(actionName)?.id
log.warn "actionId: " + actionId

// the name of the issue link type (taking into account the link direction - inward/outward)
final issueLinkName = 'Relates'

// if it's a Feature that's transitioning, don't run this script
if (issue.issueType.name == 'Feature') {
return
}

// find the Feature(s) linked to/from this issue
def featureInward = issueLinkManager.getInwardLinks(issue.id).findAll { it.issueLinkType.name == issueLinkName }?.sourceObject
def featureOutward = issueLinkManager.getOutwardLinks(issue.id).findAll { it.issueLinkType.name == issueLinkName }?.destinationObject
def features = featureInward + featureOutward
log.warn "featureInward: " + featureInward
log.warn "featureOutward: " + featureOutward
log.warn "features: " + features

features.each { feature ->

def issueInputParameters = issueService.newIssueInputParameters()

def transitionValidationResult = issueService.validateTransition(user, feature?.id, actionId, issueInputParameters)
assert transitionValidationResult.isValid(): transitionValidationResult.errorCollection

def transitionResult = issueService.transition(user, transitionValidationResult)
assert transitionResult.isValid(): transitionResult.errorCollection
}

I hope that this helps!

If this response has answered your question, please do mark it as Accepted to make it easier for other users to discover potential solutions to their questions.

Suggest an answer

Log in or Sign up to answer