Hello Community,
I am trying to develop a ScriptRunner Script that will allow me to transition an Epic to completion once all of the Stories/Tasks/Defects/Subtasks under it are completed.
Could someone point me in the right direction to achieve such functionality.
I appreciate your help!
-Roberto
Hi Roberto,
Hopefully is not too late but I crafted a post function, that should be put into the "Closed" step in the workflow. Hopefully you will understand the logic from the comments added in the code, if not, please shout :)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.workflow.TransitionOptions
def issue = issue as MutableIssue
def user = ComponentAccessor.userManager.getUserByKey("admin")
parentIssue = issue.isSubTask() ? issue.parentObject :
ComponentAccessor.getIssueLinkManager().getInwardLinks(issue.id)?.find {it.issueLinkType.name == "Epic-Story Link"}?.sourceObject
if (!parentIssue) {
// there is not any Epic issue as source so do nothing
return
}
log.debug "Parent issue $parentIssue"
// check if the parent issue has any subtasks that are not closed
def openSubtasks = parentIssue?.subTaskObjects?.findAll {it.status.name != "Done"}
log.debug "Open subtasks $openSubtasks"
// if there are subtasks that are not open (apart from the one in transition) - then do nothing
if (openSubtasks - issue) {
return
}
// get all the open linked (with the epic-story link) issues and are not closed
def linkedIssues = ComponentAccessor.getIssueLinkManager().getOutwardLinks(parentIssue.id)?.findAll {it.issueLinkType.name == "Epic-Story Link"}*.destinationObject?.findAll {it.status.name != "Done"}
log.debug "Open linded issues $linkedIssues"
// if there are linked issues that are open (apart from the one in transition) - then do nothing
if (linkedIssues - issue) {
return
}
// if the script reached here means that all the subtasks and the linked - with the Epic Story link - issues are closed
// therefore transit the issue
transitIssue(parentIssue, 41, user)
def transitIssue(Issue issue, int actionId, ApplicationUser cwdUser) {
def issueService = ComponentAccessor.getIssueService()
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("This is a comment")
issueInputParameters.setSkipScreenCheck(true)
def transitionOptions= new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()
def transitionValidationResult =
issueService.validateTransition(cwdUser, issue.id, actionId, issueInputParameters, transitionOptions)
if (transitionValidationResult.isValid()) {
return issueService.transition(cwdUser, transitionValidationResult).getIssue()
}
log.error "Transition of issue ${issue.key} failed. " + transitionValidationResult.errorCollection
}
Please let me know if this does the trick.
Regards,
Thanos
Hello Thanos,
thank you for sharing your programming code. I've tried it but it didn't work at our company. I guess maybe it is because of the action id? May I ask how could I find the action id, or why you used 41 in the programming?
Thank you a lot!
Best,
Jerry
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jerry
In order to find the transition id of the step you have to navigate to the desired workflow and then change the display from diagram to Text and then you will see a column with Transition names and their ids, something like
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thanos,
but unfortunately it still didn't work. I have no idea why not :(
thanks
Best,
Jerry
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please check your application logs for errors ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.