Hi All,
Can you help me out in auto-transition of parent issue to closed when all its linked issues are closed within the same project. (Adaptavist Scriptrunner)
waiting for an early reply.
thanks
Harish Kumar
Hello @Harish Kumar,
Scriptrunner provides a build-in post-function to do this.
Create a post-function on the transition to close in every subtask workflow. Select "Script Post-Function [ScriptRunner]" then "Transition parent when all subtasks are resolved".
This will look at the resolution of every subtasks of the parent, if all subtasks have a resolution it will make the transition.
Regards,
Adrien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry I read parent and in my mind I stucked with subtask.
You can use this script: https://library.adaptavist.com/entity/close-an-epic-when-all-the-issues-under-that-epic-are-closed
You should change:
You should put this script as a custom post-function of closing transition on every worfklow of issue that can be linked by the issueLinkName link type.
Regards,
Adrien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@SITTER Adrien Hi, I have edited the code, and the final code looks like this:
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 String actionName = "Closed"
// the name of the issue link
final String issueLinkName = "Cloners"
def workflow = ComponentAccessor.workflowManager.getWorkflow(issue)
def actionId = workflow.allActions.findByName(actionName)?.id
def issueLinkManager = ComponentAccessor.issueLinkManager
def epicIssue = issueLinkManager.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 completed
def linkedIssues = issueLinkManager
.getOutwardLinks(epicIssue.id)
.findAll { it.issueLinkType.name == issueLinkName }
*.destinationObject?.findAll { it.status.statusCategory.name != "Closed" }
// If there are still open linked issues (except the one in transition) - then do nothing
if (linkedIssues - issue) {
return
}
def issueService = ComponentAccessor.issueService
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("This Issue closed automatically because all the linked-issues in this Issue are closed.")
issueInputParameters.setSkipScreenCheck(true)
def transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def transitionValidationResult = issueService.validateTransition(loggedInUser, epicIssue.id, actionId, issueInputParameters, transitionOptions)
assert transitionValidationResult.isValid() : transitionValidationResult.errorCollection
def result = issueService.transition(loggedInUser, transitionValidationResult)
assert result.isValid() : result.errorCollection
Query : I need to put this code in the workflow transition of all linked issues and parent issues where the final status is there ? can you explain me please.
Thanks
HArish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So from what I see you have a parent issue which is linked to other issue with "is cloned by" relation (which names is "Cloners"). This is one of the default issue linking relation of Jira.
The issues that are linked to your parent issue have one or several workflows (if you have different issues type with different workflow).
For each of this workflow you have to edit every transition making your issue going to a "Closed" states (that can be one or several, depending of your workflow). For each of this transition, add a post-function of type "Script Post-Function [ScriptRunner]" > "Custom script post-function" and paste the code you have adapted.
Regards,
Adrien
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I just saw that you change
it.status.statusCategory.name != "Complete"
To
it.status.statusCategory.name != "Closed"
This will not work. This line does not look for the status name but the status category name which can only be "New", "In Progress" or "Complete"
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.
Hi @SITTER Adrien , will you please help me too?
I try to make the same process work in Service Desk type project. The status categories there are "To Do", "In Progress", "Done". I changed the code you provided for my case, but it didn't work, will you please have a look and tell me the reason?
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 String actionName = "Resolved"
// the name of the issue link
final String issueLinkName = "Problem/Incident"
def workflow = ComponentAccessor.workflowManager.getWorkflow(issue)
def actionId = workflow.allActions.findByName(actionName)?.id
def issueLinkManager = ComponentAccessor.issueLinkManager
def epicIssue = issueLinkManager.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 completed
def linkedIssues = issueLinkManager
.getOutwardLinks(epicIssue.id)
.findAll { it.issueLinkType.name == issueLinkName }
*.destinationObject?.findAll { it.status.statusCategory.name != "Done" }
// If there are still open linked issues (except the one in transition) - then do nothing
if (linkedIssues - issue) {
return
}
def issueService = ComponentAccessor.issueService
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setComment("This Issue closed automatically because all the linked-issues in this Issue are closed.")
issueInputParameters.setSkipScreenCheck(true)
def transitionOptions = new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def transitionValidationResult = issueService.validateTransition(loggedInUser, epicIssue.id, actionId, issueInputParameters, transitionOptions)
assert transitionValidationResult.isValid() : transitionValidationResult.errorCollection
def result = issueService.transition(loggedInUser, transitionValidationResult)
assert result.isValid() : result.errorCollection
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.