Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
badges earned

Your Points Tracker
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Script Listener Updates Custom Field to Wrong Value-Cloud

I have a script listener on issue updates that copies the latest value in the Sprint field to another read-only custom field called 'Current Sprint.' So anytime the Sprint field is updated, the Current Sprint field is updated as well. 

It mostly works well, but I'm having a problem when issues aren't completed in a sprint & are rolled over to the next sprint. Ex. The Sprint field shows an issue is in Canopy Sprint 15, but Current Sprint says Canopy Sprint 14, the previous sprint. If I try to update this manually, either through a bulk edit or the Scriptrunner script console, it works but then my script listener immediately runs & sets it back to the previous, incorrect sprint. Any ideas on what's causing this, or ways to improve my script? I'm newer to scripting so I'm sure this could be improved a bit. 

def issueTypes = ['Story', 'Epic']
def thing

if (! in issueTypes) {

def issueKey = issue.key

def returnLatestSprintName(issueSprints) {
def latestSprint
if (issue.fields.customfield_10115) {
def sprints = []
issueSprints.each { sprint ->
def sprintMap = sprint.substring(sprint.indexOf('[')+1, sprint.indexOf(']')).tokenize(',').collectEntries { [(it.tokenize('=')[0]): it.tokenize('=')[1] ]}
//sprints.sort { }

latestSprint = sprints.sort { }[-1].name
} else {
latestSprint = ''
return latestSprint

def latestSprint = returnLatestSprintName(issue.fields.customfield_10115)

if (issue.fields.customfield_10752 != latestSprint && latestSprint != '') {
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
fields: [
customfield_10752: latestSprint


2 answers

Hi Keri,


I had a little script that does something like that, I adapted it a bit to your requirements and it works fine for me. You could try it and I hope it works to you:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption

def cfManager = ComponentAccessor.customFieldManager
def issueManager = ComponentAccessor.issueManager

def currentSprint = cfManager.getCustomFieldObject(11101L) //Replace ID with your custom field ID
def sprint = cfManager.getCustomFieldObject(10104L) //Replace ID with your original sprint ID

def invalidIssueTypes = ["Story", "Epic"]

issue.setCustomFieldValue(currentSprint, Arrays.toString(sprint.getValue(issue).name).replace("[", "").replace("]", ""))

issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.DO_NOT_DISPATCH, false)


I tried it two ways:
- Moving issue between sprints on backlog view.
- Editing Sprint field

Both of them work as expected.



Marcos your code is for Jira Server not Jira Cloud, so it won't work for Keri.

Oh, right.

I absolutely forgot about the cloud, so sorry...

Hi Keri,

I'm not sure how to do this programmatically because the Jira Software REST APIs don't give enough of the information you need.

Could you just temporarily disable your Script Listener whenever you manually fix the issues?


Suggest an answer

Log in or Sign up to answer
Community showcase

The benefits of using Jira in different departments

Jira is a great tool to use across different departments. Forget that paperwork – switch to Jira and get that tasks done smoothly. Marketing Jira allows for a complete digital transformation of you...

75 views 0 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you