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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,552,506
Community Members
 
Community Events
184
Community Groups

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

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

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 05, 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

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 05, 2022 • edited

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 03, 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 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events