Sprint Create Event

How to use Sprint Started Event in the scriptrunner to create an issue during the start of the Sprint ?

 

Please provide the details

2 answers

1 accepted

Hi Manikandan,

The script below will create an issue and it will add it to the sprint that started and triggered the event.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.PriorityManager

def issueFactory = ComponentAccessor.getIssueFactory()
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def newIssue = issueFactory.getIssue()
def project = ComponentAccessor.projectManager.getProjectByCurrentKey("SSPA")
def bugIssueType = ComponentAccessor.constantsManager.getAllIssueTypeObjects().find { it.getName() == "Bug" }
def highPriority = ComponentAccessor.getComponent(PriorityManager).getPriority("High")
def reporter = ComponentAccessor.userManager.getUserByKey("anuser")
def sprintCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sprint")

newIssue.setSummary("A summary")
newIssue.setProjectObject(project)
newIssue.setIssueType(bugIssueType)
newIssue.setPriority(highPriority)
newIssue.setReporter(reporter)
newIssue.setCustomFieldValue(sprintCF, [event.sprint]) //add the issue to the sprint that just started and triggered the event
//... any other fields

Map<String,Object> newIssueParams = ["issue" : newIssue] as Map<String,Object>
ComponentAccessor.issueManager.createIssueObject(loggedInUser, newIssueParams)

So eventually your listener will listen for Sprint Started event and the script will be the above.

I'll agree with Anton that a use case will be more helpful. 

PS. In your question's title you say sprint create event which is a different event than the Sprint Started Event.

So your custom script listener will look like  

Screen Shot 2017-11-08 at 15.47.30.png

 

Hope that helps,

Thanos

@Thanos Batagiannis [Adaptavist] - Thanks this helps to move forward.

I receive below error after configuration.Let me know your suggestions

 

Time (on server): Wed Nov 08 2017 15:31:58 GMT-0500 (Eastern Standard Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-11-08 20:31:58,570 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2017-11-08 20:31:58,570 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.greenhopper.api.events.sprint.SprintStartedEvent, script: com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.FireEventWhen
java.lang.IllegalArgumentException: The issue object was not available in the binding, perhaps called from an event handler with a non-issue event
 at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.FireEventWhen.doScript(FireEventWhen.groovy:72)

Cancelscript.jpg

Hey Manikandan,

The listener should be a Custom Listener

I have a similar requirement but unfortunatly can't find any Sprint..Event.
I'm using Jira Software 7.0.4. with ScriptRunner 5.1.6

Did this event appear with a later version?


Regards,

Christian

0 vote
Anton Chemlev Community Champion Nov 08, 2017

Am i right - you want to create issue in some project when clicked "Start sprint" on the board?

Could you please provide more details - what problem are you trying to solve?

Yes. You are right. I would like to create an issue, when i click Start Sprint. a Default issue type "Feature" will be added to the Sprint. 

I tried its not working as expected in the script runner. Need some help on it

 

script.jpg

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

892 views 3 12
Read article

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