So I built a script post-function based on one I found from Jamie about setting an issue to a sprint (mine sets based on a custom field). This script works fine on JIRA 6, but upgrading to JIRA 7, it's throwing me an error:
"[Static type checking] - Cannot find matching method com.atlassian.greenhopper.service.sprint.SprintIssueService#addIssuesToSprint(com.atlassian.jira.user.ApplicationUser, java.lang.Object, java.util.List). Please check if the declared type is right and if the method exists."
I know the API has changed up a bit and is no longer working with GenericValues, but even after I started casting all my variables (which, on all of my other scripts, I haven't yet had to do), it still throws only this error.
Is there something that's changed about the addIssuesToSprint function? Or do I just need to cast my variables in better ways? Thanks!
import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.greenhopper.service.sprint.SprintService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Category
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
//Set Variables
log.setLevel(org.apache.log4j.Level.INFO)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfSprint = customFieldManager.getCustomFieldObjectByName("Sprint")
def cfAgileBoard = customFieldManager.getCustomFieldObjectByName("Agile Board")
def sprints = issue.getCustomFieldValue(cfSprint)
def agileBoard = issue.getCustomFieldValue(cfAgileBoard)
def rapidBoardId = 0
//See if the issue is already in an active sprint
if (sprints != null) {
for (i in sprints.size) {
ii = i-1
isprint = sprints.get(ii)
istate = isprint.state.toString()
if (istate == "ACTIVE") {
log.info("Issue is already in active sprint")
return
}
}
}
//Sets to a specific board for all issues in a certain project
if (issue.getProjectObject().getKey() == 'KEY') {
setBoard(18)
return
}
//Sets to an agile board based on a custom field
switch (agileBoard) {
case "Agile Board 1":
setBoard(30)
break
case "Agile Board 2":
setBoard(39)
break
case "Agile Board 3":
setBoard(31)
break
case "Agile Board 4":
setBoard(32)
break
case "Agile Board 5":
setBoard(33)
default:
log.info("Agile Board field is empty")
return
break
}
//Performs the actual sprint setting
public setBoard(rapidBoardId) {
@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean
RapidViewService rapidViewService
@JiraAgileBean
SprintService sprintService
@JiraAgileBean
SprintIssueService sprintIssueService
@JiraAgileBean
SprintManager sprintManager
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def view = rapidViewService.getRapidView(loggedInUser, rapidBoardId).getValue()
def boardSprints = sprintManager.getSprintsForView(view).getValue()
def activeSprint = boardSprints.find { it.active }
def boardName = view.getName()
if (activeSprint) {
sprintIssueService.addIssuesToSprint(loggedInUser, activeSprint, [issue])
log.info("Auto-setting Sprint to active sprint of board: $boardName")
}
else {
log.info("$boardName has no active sprint")
}
return
}