Script Listener to notify of Sprint field changes in OpenSprints()

Hello

We want to be notified when a sprint field is changed.

We know this can be accomplished with the following query in the condition of a script listener:

changeItems.any{
it.field == 'Sprint'
}

However, this triggers when any sprint field is changed which is not what we want.

We only want this to be triggered if the ticket is in an OpenSprint() and dont know how to do this.

Any help on this would be great.

Thanks

Adam

1 answer

Hi Adam,

A colleague of mine helped me put this one together (thanks Ash). Please try this (untested):

import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.service.sprint.SprintIssueService
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
 
List changeItems = event?.getChangeLog()?.getRelated("ChildChangeItem")
def issue = event.issue

def sprintIssueService = PluginModuleCompilationCustomiser.getGreenHopperBean(SprintIssueService)
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

def serviceOutcome = sprintIssueService.getSprintsForIssue(user, issue)
def sprints = serviceOutcome.get()
def isActiveSprint = sprints*.state.every{ it == Sprint.State.ACTIVE}

def isSprintFieldModified = changeItems.any{
    it.field == 'Sprint'
}

isSprintFieldModified && isActiveSprint

Hi

I have not used this yet.

Are you sure this will trigger the email when a change is made to a ticket in an open sprint?

It seems to be a lot to add to the initial code for such a small request.

Thanks

Adam

Hi Adam,

As mentioned it is untested, so I'm not sure but I'll leave it to you to test it in your staging environment.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,847 views 12 18
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot