Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage
Highlighted

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

How to create Jira issus from Excel file?

When to use CSV importer When managing your processes in Jira, there are many occasions where you need to create a lot of tasks. Creating them one by one will cost you a lot of time and effort and i...

4,487 views 22 32
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