Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,297,946
Community Members
 
Community Events
165
Community Groups

How to update multiple issues when sprint start with a listener script runner

I paste my code created: is working perfectly!

1) I got to the Script Listener menu

2) Here, I select the Custom Script

3) In the Custom Script Menu, I enter the name "Test",  the event that I select is "Sprint Started Event",  and I insert the code above into the Inline Script.

4) To proceed, I need to know what is the id of the status i.e. actionId.  
To explain, below I have added another video which displays the Workflow. From here I select the view option to view workflow which I am going to use i.e. SIMP.

Once I'm in the workflow page, I can see the Transitions (id). The transition name is what I am going to use in the if / else condition i.e.

this is the code attached:





com.atlassian.greenhopper.service.rapid.view.RapidViewService import com.atlassian.greenhopper.service.sprint.Sprint import com.atlassian.greenhopper.web.rapid.chart.HistoricSprintDataFactory import com.atlassian.jira.component.ComponentAccessor import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser import com.onresolve.scriptrunner.runner.customisers.WithPlugin @WithPlugin("com.pyxis.greenhopper.jira") def historicSprintDataFactory = PluginModuleCompilationCustomiser.getGreenHopperBean(HistoricSprintDataFactory) def rapidViewService = PluginModuleCompilationCustomiser.getGreenHopperBean(RapidViewService) def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser() def sprint = event.sprint as Sprint def sprintState = sprint.state if (sprintState == Sprint.State.ACTIVE) { def view = rapidViewService.getRapidView(user, sprint.rapidViewId).value def sprintContents = historicSprintDataFactory.getSprintOriginalContents(user, view, sprint) def sprintData = sprintContents.value def issueService = ComponentAccessor.getIssueService() // this is the id of the transition you want to make // to get the transition ID, you can refer to your workflows def actionId = 21 if (sprintData) { def issues = sprintData.contents.issuesNotCompletedInCurrentSprint issues.each { issue -> def issueId = issue.id log.warn issue.statusName //to get the status name if(issue.statusName == "To Do" || issue.statusName == "In Progress") { def issueInputParameters = issueService.newIssueInputParameters() def transitionValidationResult = issueService.validateTransition(user, issueId, actionId, issueInputParameters) if (transitionValidationResult.isValid()) { issueService.transition(user, transitionValidationResult) } else { log.warn transitionValidationResult.errorCollection.errorMessages } } else { log.warn "Nothing to do" } } } }

 

1 comment

one update based in the skip of validations conditions and permissions:

 

import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.web.rapid.chart.HistoricSprintDataFactory
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.workflow.TransitionOptions

@WithPlugin("com.pyxis.greenhopper.jira")
def historicSprintDataFactory = PluginModuleCompilationCustomiser.getGreenHopperBean(HistoricSprintDataFactory)
def rapidViewService = PluginModuleCompilationCustomiser.getGreenHopperBean(RapidViewService)

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def sprint = event.sprint as Sprint
def sprintState = sprint.state

if (sprintState == Sprint.State.ACTIVE) {
def view = rapidViewService.getRapidView(user, sprint.rapidViewId).value
def sprintContents = historicSprintDataFactory.getSprintOriginalContents(user, view, sprint)
def sprintData = sprintContents.value
def issueService = ComponentAccessor.getIssueService()


// this is the id of the transition you want to make
// to get the transition ID, you can refer to your workflows
def actionId = 181

if (sprintData) {
def issues = sprintData.contents.issuesNotCompletedInCurrentSprint

issues.each { issue ->

def issueId = issue.id

log.warn issue.statusName //to get the status name

if(issue.statusName == "Nueva" || issue.statusName == "En Refinamiento" || issue.statusName == "Refinada") {

def issueInputParameters = issueService.newIssueInputParameters()

// conditions, permissions and validations are disabled
def transitionOptions= new TransitionOptions.Builder()
.skipConditions()
.skipPermissions()
.skipValidators()
.build()

def transitionValidationResult = issueService.validateTransition(user, issueId, actionId, issueInputParameters, transitionOptions)

if (transitionValidationResult.isValid()) {
issueService.transition(user, transitionValidationResult)
} else {
log.warn transitionValidationResult.errorCollection.errorMessages
}
} else {
log.warn "Nothing to do"
}
}
}
}

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Jira Software

Upcoming changes to epic fields in company-managed projects

👋 Hi there Jira Community! A few months ago we shared with you plans around renaming epics in your company-managed projects. As part of these changes, we highlighted upcoming changes to epics on...

14,797 views 37 48
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you