Update sprint field thru script runner

Maha vishnu v April 16, 2020

Can any one help  me on fixing this code ? Purpose is to update the Sprint field values manually  , but its not working 
import com.atlassian.jira.issue.IssueManagerimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.issue.ModifiedValueIssueManager im = ComponentAccessor.getIssueManager()MutableIssue issue = im.getIssueObject("PROD-2458")
if(issue){
 //get the value
    def customFieldManager = ComponentAccessor.getCustomFieldManager()
    def cField = customFieldManager.getCustomFieldObject("customfield_10504")
    def cFieldValue = issue.getCustomFieldValue(cField)
// return cFieldValue
 //update the value
 def changeHolder = new DefaultIssueChangeHolder()
  cField.updateValue(null, issue, new ModifiedValue(cFieldValue, "June'20_Sprint4"),changeHolder)
}else {    return "Issue doesn't exist"}

1 answer

1 vote
Juan José Marchal Gómez
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2021

Hello @Maha vishnu v ,

this code update the sprint. I hope it helps.
Best regards.

 

 

 

import groovy.json.JsonOutput
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.greenhopper.manager.issuelink.EpicLinkManager
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.service.sprint.SprintManager
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.user.ApplicationUser
@WithPlugin("com.pyxis.greenhopper.jira")
@JiraAgileBean
SprintManager sprintManager
@JiraAgileBean
SprintIssueService sprintIssueService

def sprintId = //here your sprint Id
def currentSprint = sprintManager.getSprint(sprintId).getValue()
log.warn currentSprint

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = issueManager.getIssueObject(IssueKey) //your issue key
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

def cfSprint = customFieldManager.getCustomFieldObjects(issue).findByName("Sprint")

def sprints = []
sprints.add(currentSprint)

cfSprint.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cfSprint), sprints), new DefaultIssueChangeHolder())
mfabris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 10, 2022

Probably needs to be cleaned up a bit but it does work. 

thanks!

Suggest an answer

Log in or Sign up to answer