Help with Listener on SprintStartedEvent- Copy Custom Field Value to Assignee

Chelsea May 3, 2022

I am trying to create a Custom Listener that fires on the SprintStartedEvent. 

What I want for the outcome is when a Sprint is started the value that is in the custom field "Planned Assignee" which is a single user picker field will be copied into the Assignee field. 

 

I am not sure how to get this started. I haven't been able to find any previous questions asked that are helpful in this situation. 

 

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Chelsea May 5, 2022

Thanks for links to the documentation. It has not proved to be terribly helpful. 

This is the script that I have cobbled together looking at various examples of things that are sorta close. 

codeshot.png

You can see that the event.issue is causing a problem and that is what the log references: 

2022-05-05 10:50:35,729 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2022-05-05 10:50:35,729 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.greenhopper.api.events.sprint.SprintStartedEvent, file: null
groovy.lang.MissingPropertyException: No such property: issue for class: com.atlassian.greenhopper.api.events.sprint.SprintStartedEvent
at Script993.run(Script993.groovy:7)

I am not sure how to get around that.  I can't even start to see how the rest of the code is messed up while that is erroring.  

I see I did not mention this in the OP, I am using Jira Data Center 8.20.1. Looks like ScriptRunner is on 6.49. 

Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2022

Yes the event is a sprint event and not an issue event.  You need to get the issues out of the sprint event as per the example in the Library (although that's for the closed event the logic is basically the same). 
So this line here the value would be null.  def issue = event.issue as issue

Chelsea May 5, 2022

So in the example, everything above line 21 if (sprintData) is somehow grabbing the issues from the Sprint. Okay. I still don't understand at all how I would call the custom field "Planned Assignee" and use that to populate the Assignee field because the only way I know how to do that is using script with issue in it (issue.assignee, event.issue, etc). 

If the example is somehow showing that then I do not understand how. 

 

 

Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2022

I'm really sorry I can't test for you but you need to try something along these lines.

import com.atlassian.greenhopper.service.rapid.view.RapidViewService
import com.atlassian.greenhopper.service.sprint.Sprint
import com.atlassian.greenhopper.web.rapid.chart.HistoricSprintDataFactory
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.PluginModuleCompilationCustomiser
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.workflow.TransitionOptions

@WithPlugin("com.pyxis.greenhopper.jira")
def historicSprintDataFactory = PluginModuleCompilationCustomiser.getGreenHopperBean(HistoricSprintDataFactory)
def rapidViewService = PluginModuleCompilationCustomiser.getGreenHopperBean(RapidViewService)

def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def sprint = event.sprint as Sprint
def sprintState = sprint.state

if (sprintState == Sprint.State.ACTIVE) {
def view = rapidViewService.getRapidView(user, sprint.rapidViewId).value
def sprintContents = historicSprintDataFactory.getSprintOriginalContents(user, view, sprint)
def sprintData = sprintContents.value
def issueService = ComponentAccessor.getIssueService()

 


if (sprintData) {
def issues = sprintData.contents.issuesNotCompletedInCurrentSprint

issues.each { issue ->

def issueId = issue.id

def sourceField = customFieldManager.getCustomFieldObjectByName("Planned Assignee")

// put the rest of your code here

thispart.JPG

}
}

0 votes
Craig Nodwell
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 3, 2022

Hi @Chelsea welcome to the community.
I'd suggest you start here, there's lots of examples.

Jira Server:

  1. Scriptrunner What are Listeners 
  2. In the custom scripts there's an example with the sprintclosed event you can review.
    Scriptrunner Custom listeners 
  3. Another great resource is the Script Library
    Scriptrunner Library 

Jira Cloud:

  1. Scriptrunner Listeners 
  2. Scriptrunner listener examples 
  3. Scriptrunner Library Cloud 
  4. Code Snippets Repository 
TAGS
AUG Leaders

Atlassian Community Events