Hi community,
I'm brand new to Groovy Scripts, currently using Jira Server v8.14.0.
I am trying to implement a script post-function using ScriptRunner which will transition an Epic to Done if all childs (Story,Task or Bug) are Done using a Script from Adaptavist Library and it is working. If I use the same script changing the issueLinkType (Parent-Child Link), Initiative will be transitioned to Done if all childs(Epic) are Done.
I have use them separately (one script for Epic & one for Initiative) in the same transition (to Done) and it is working, is it possible to have one script for both Epic&Initiative instead of two for this purpose?
Any guidance would be very appreciated.
Thank you!
https://library.adaptavist.com/entity/close-an-epic-when-all-the-issues-under-that-epic-are-closed
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.TransitionOptions
// the name of the action you want to move the issue to
final actionName = 'Close'
//Name of the resolution children issues should have
final resolutionName = 'Done'
// the name of the issue link
final issueLinkName = 'Epic-Story Link'
def workflow = ComponentAccessor.workflowManager.getWorkflow(issue)
def actionId = workflow.allActions.findByName(actionName)?.id
def linkManager = ComponentAccessor.issueLinkManager
def epicIssue = linkManager.getInwardLinks(issue.id).find { it.issueLinkType.name == issueLinkName }?.sourceObject
if (!epicIssue) {
return
}
// Find all the linked - with the "Epic-Story Link" link - issues that their status is not the same as resolutionName
def linkedIssues = linkManager
.getOutwardLinks(epicIssue.id)
.findAll { it.issueLinkType.name == issueLinkName }
*.destinationObject?.findAll { it.resolution?.name != resolutionName }
// If there are still open linked issues (except the one in transition) - then do nothing
if (linkedIssues - issue) {
return
}
def issueService = ComponentAccessor.issueService
def inputParameters = issueService.newIssueInputParameters()
inputParameters.setComment('This Epic closed automatically because all the issues in this Epic are closed.')
inputParameters.setSkipScreenCheck(true)
def transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def transitionValidationResult = issueService.validateTransition(loggedInUser, epicIssue.id, actionId, inputParameters, transitionOptions)
assert transitionValidationResult.valid: transitionValidationResult.errorCollection
def result = issueService.transition(loggedInUser, transitionValidationResult)
assert result.valid: result.errorCollection