Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,363,993
Community Members
 
Community Events
168
Community Groups

Update sprint field thru script runner

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

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())

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

thanks!

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events