I need to change value of Sprint(for example, Name) of concrete issue. When i try simply update sprint, it appearances the next error: 'Java.lang.String cannot be cast to java.util.Collection'. How can i change necessary elements in this collection?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
def issueManager = ComponentAccessor.getIssueManager()
def curIssue = issueManager.getIssueObject("MyIssue")
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def curUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customField = customFieldManager.getCustomFieldObjectByName("Sprint")
curIssue.setCustomFieldValue(customField, "sprint4 (18/10/16-31/10/16)")
issueManager.updateIssue(curUser, curIssue, EventDispatchOption.ISSUE_UPDATED, false)
Community moderators have prevented the ability to post new answers.
Ok John,
If you want to update the name of the sprint itself then for a JIRAv7 try
import com.atlassian.greenhopper.service.sprint.Sprint import com.atlassian.greenhopper.service.sprint.SprintManager import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser import com.onresolve.scriptrunner.runner.customisers.WithPlugin @WithPlugin("com.pyxis.greenhopper.jira") def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager) def sprintServiceOutcome = sprintManager.getAllSprints() if (sprintServiceOutcome.valid) { def sprint = sprintServiceOutcome.getValue().find {it.name == "Sprint Name"} as Sprint if (!sprint) { log.debug "Could not find sprint with name <Sprint Name>" } else { def newSprint = sprint.builder(sprint).name("New Name").build() def outcome = sprintManager.updateSprint(newSprint) if (outcome.isInvalid()) { log.debug "Could not update sprint with name : Sprint 2 because ${outcome.getErrors()}" } else { log.debug "Sprint Updated !!" } } }
please let me know if this does the trick
Thank you! This worked well, when I needed to update a groovy script from Jira v6.1 to Jira v7.3
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try this code:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue MutableIssue curIssue = ComponentAccessor.getIssueManager().getIssueObject("MyIssue") curIssue.setCustomFieldValue( ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Sprint") , Arrays.asList("sprint4 (18/10/16-31/10/16)")) issueManager.updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser() , curIssue , EventDispatchOption.ISSUE_UPDATED , false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi John,
If you want to update the issue's sprint to one that exist and not update a property of the sprint itself (for example the name) you should get the Sprint Object and then set the custom field value. So in order to get the Sprint itself try something like
import com.atlassian.greenhopper.service.sprint.SprintManager import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser import com.onresolve.scriptrunner.runner.customisers.WithPlugin @WithPlugin("com.pyxis.greenhopper.jira") def sprintManager = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintManager) def sprintServiceOutcome = sprintManager.getAllSprints() if (sprintServiceOutcome?.valid) { def sprint = sprintServiceOutcome.getValue().find {it.name == "Sprint 1"} if (!sprint) { log.debug "Could not find sprint with name <SPrint 1>" } else { // do something with this sprint } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Thanos!
I want to update property of the sprint(just name). I try to use this script and get the next error: "Cannot set readonly property". Is it real to change name of object Sprint?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.jira.event.type.EventDispatchOption
def issueManager1 = ComponentAccessor.getIssueManager();
def curIssue1 = issueManager1.getIssueObject("IssueName")
def customFieldManager1 = ComponentAccessor.getCustomFieldManager()
def Name = customFieldManager1.getCustomFieldObjectByName("Sprint")
ArrayList<Sprint> sprints = (ArrayList<Sprint>)curIssue1.getCustomFieldValue(Name)
sprints.get(0).putAt("name","dsa")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist] , I created a script to auto update the Sprint based on a change in the issue, but it seems like it is removing all the Completed Sprints when the automation ran, any possible solution for this?
Do you think instead of adding the sprint an update is required for this?
Check the excerpt below:
// else
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setSkipScreenCheck(true)
issueInputParameters.addCustomFieldValue(sprintCustomFieldId, sprint?.id as String)
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def validationResult = issueService.validateUpdate(user, issue.id, issueInputParameters)
if (validationResult.isValid()) {
issueService.update(user, validationResult)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.