Heads up! On March 5, starting at 4:30 PM Central Time, our community will be undergoing scheduled maintenance for a few hours. During this time, you will find the site temporarily inaccessible. Thanks for your patience. Read more.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to modify the Sprint end date using ScriptRunner?

Stefan Stadler
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.
October 29, 2024

Hi all,

I am trying to modify the sprint end date for some conditions. For testing purposes, I want to set it to the current date, but it does not appear to be changed at all. Manually changing is possible, so there is no question of permissions.

This is my script for changing it:

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.IssueManager

import com.atlassian.jira.issue.fields.CustomField

import com.onresolve.scriptrunner.runner.customisers.JiraAgileBean

import com.atlassian.greenhopper.service.sprint.Sprint

import com.atlassian.greenhopper.service.sprint.SprintManager

import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin(['com.pyxis.greenhopper.jira',])

IssueManager issueManager = ComponentAccessor.getIssueManager()

def issue = issueManager.getIssueObject("issueKey")

@JiraAgileBean

SprintManager sprintManager

CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager()

def cf = cfManager.getCustomFieldObjects(issue).find { CustomField it -> it.name == 'Sprint'}

List<Sprint> sprints = issue.getCustomFieldValue(cf) as List<Sprint>

def outcome = sprintManager.updateSprint(Sprint.builder(sprints.last()).endDate(new Date().clearTime().time).build())

log.warn(outcome)

if(outcome.isInvalid()) {

    log.warn('Outcome invalid')

}


It is absolutely strange as the first log is showing the Sprint with the updated end date. However, it appears that the update of the sprint is somehow not persisted in the system.
Can you let me know, what I may do wrong here?
Thanks!
Stefan

1 answer

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 29, 2024

Hi @Stefan Stadler

Could you please clarify how you are trying to trigger the update? Are you doing this via Post-Function or ScriptRunner Console?

I am looking forward to your feedback and clarification.

Thank you and Kind regards,
Ram

Stefan Stadler
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.
October 29, 2024

Hi @Ram Kumar Aravindakshan _Adaptavist_ 

the plan is to handle this in a listener, whenever the date of a certain issue type (which is assigned to the sprint only once) is changing. To keep this issue in sync with the sprint dates.

But for now, I am trying to achieve this by using the Script Console for testing purposes. So the above script is to be running from the Script Console.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
9.4.1
TAGS
AUG Leaders

Atlassian Community Events