Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can transitions of Story automatically trigger the necessary transitions for Feature?

Mani August 1, 2018

For Example: If i have 3 stories linked to a Feature and one them moved to "To do" to "In Progress" the Feature should also change to "In Progress".

Same way if all the three stories moved to "Done" the Feature should also changed to "Done".

We don't have any customization Add-ons integrated with JIRA except Script Runner.

I am new to Script Runner and Groovy script.

How to achieve this with Script Runner?

I tried to find a solution for this in online and script runner documentation. I couldn't find way to do this.

Any help would be greatly appreciated!

Thanks,

Mani 

2 answers

0 votes
Mani August 8, 2018

Hi @JohnsonHoward

In getLinkedIssues method ,first parameter you are passing is it.sourceObject . In my scenario what exactly the parameter value would be?

In same way it.destinationObject what value do i need to pass, if it has to be done dynamically.

JohnsonHoward
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 9, 2018

Hi Mani,

Please read this Community answer to understand the difference between a source and destination object. 

In this instance the 'it' is an issue link between a story and a feature. You will need to determine if the Feature issue is the source or destination as you are trying to get the linked issue for the feature on the line you have mentioned.

Thanks
Johnson

0 votes
JohnsonHoward
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2018

Hi Manikanta,

You are probably looking for something like this:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser
import groovy.transform.Field
@Field ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

Issue issue = event.issue



if(issue.issueType.name == "Story" && issue.status.name == "In Progress"){
def features = getLinkedIssues(issue, "Feature of")
def inProgressActionId = 100
features.each {
tranistionIssue(it.sourceObject, inProgressActionId)
}

}else if(issue.issueType.name == "Story" && issue.status.name == "In Progress"){
def features = getLinkedIssues(issue, "Feature of")
def doneActionId = 200
features.each {
def storiesInFeature = getLinkedIssues(it.sourceObject, "Features")
def allInDoneStatus = true
storiesInFeature.each {
if(it.destinationObject.status.name != "Done"){
allInDoneStatus = false
}
}

if(allInDoneStatus){
tranistionIssue(it.sourceObject, doneActionId)
}
}
}

def getLinkedIssues(Issue issue, def linkType){

IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
List<IssueLink> linkedIssue = issueLinkManager.getOutwardLinks(issue.id).findAll{ it.issueLinkType.inward == linkType}
return linkedIssue

}

def tranistionIssue(def issue, actionId){
def issueService = ComponentAccessor.getIssueService()
def transitionValidationResult = issueService.validateTransition(currentUser, issue.id, actionId,new IssueInputParametersImpl())
if (transitionValidationResult.isValid()) {
def transitionResult = issueService.transition(currentUser, transitionValidationResult)
}
}

This code is not tested and you will have to play around with the variables and properties in the script, but all the concept that you need are there.

The script gets link issues, checks statuses and transitions issue.

Move it around to work for you.

Thanks
Johnson Howard 

Mani August 7, 2018

@JohnsonHoward,

Thanks for your response, I will test this script.

JohnsonHoward
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 8, 2018

Hi Manikanta,

Please don't expect this script to work by just copy and pasting it.

It will need to rewritten to fit your needs and work correctly. It was just to show all the concepts needed to get you started.

Thanks
Johnson Howard

Suggest an answer

Log in or Sign up to answer