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" } } } }
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"
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.