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

Get current sprint name and Sprint created date using script runner

I would like to get the current sprint name when ever a sprint is created . 

I also have one more field name Issue logged date where in an issue type gets automatically created when ever a sprint gets created.

How do I get current sprint name or ID and current sprint date when ever the sprint gets created .




 

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 26, 2022

If you configure an issue listener with a "Sprint Created" or "Sprint Started" or any other Sprint-related event, the event object should include a Sprint object.

So you can grab any of its values:

def boardId = event.sprint.rapidViewId
def sprintName = event.sprint.name
def sprintId = event.sprint.id
def sprintStartDate = event.sprint.startDate

Thank you so much this information. I was able to  add Sprint name for the automated sprint creation .

However ,I have a custom field date picker  named  'Sprint Logged date'

 I want to add the Sprint Create date , whenever  the sprint gets created via the listener   How do I achieve this 

  I wanted something like this Here -  newIssue.set customfeild(sprint Logged date:  event.sprint. createDate) 

My code below: 

 

import com.atlassian.jira.user.util.UserUtil
import java.util.Date.*

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("QBT")
def IssueType = ComponentAccessor.constantsManager.getAllIssueTypeObjects().find { it.getName() == "Iteration Defect Resolution" }
def sprintCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Sprint")
def boardId = event.sprint.rapidViewId
def sprintName = event.sprint.name
def sprintId = event.sprint.id
def sprintStartDate = event.sprint.startDate
//get the Date Field here

// Get sprint field from the issue fields as a Map

newIssue.setSummary("Iteration Defect Resolution created for ${sprintName} ")
newIssue.setProjectObject(project)
newIssue.setIssueType(IssueType)

 I wanted something like this Here -  newIssue.set customfeild(issue log date:  event.sprint. createDate

newIssue.setCustomFieldValue(sprintCF, [event.sprint]) //add the issue to the sprint that just started and triggered the event
//... any other fields

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 28, 2022

There is no such thing as "Sprint Create Date" in the system.

The Sprint entity contains 3 dates only: Start Date, End Date, Complete Date

It is possible to create a new issue when the sprint is created and assign that issue to the sprint immediately.

But what you need to store in your custom field will be the current date/time.

You can't use any date values from the sprint entity since all those dates will be empty at creation time. 

Here is a script to create an issue on the sprint created event:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.issuetype.IssueType
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.project.Project
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.thread.JiraThreadLocalUtil
import groovy.transform.Field

@Field IssueService issueService = ComponentAccessor.issueService
@Field Collection<IssueType> issueTypes = ComponentAccessor.constantsManager.allIssueTypeObjects
@Field ApplicationUser currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
log.info "Sprint created detected for ${event?.sprint?.name} (${event?.sprint?.id}) in board ${event?.sprint?.rapidViewId}"

//using a separate thread so the user creating the sprint doesn't have to wait for the issue creation to finish
Thread.start {
def jiraThreadLocalUtil = ComponentAccessor.getComponent(JiraThreadLocalUtil)
jiraThreadLocalUtil.preCall()
try {
ComponentAccessor.jiraAuthenticationContext.loggedInUser = currentUser
def boardId = event.sprint.rapidViewId
def sprintName = event.sprint.name
def sprintId = event.sprint.id

def project = ComponentAccessor.projectManager.getProjectObjByKey('QBT')

def issueParams = issueService.newIssueInputParameters()
issueParams.setApplyDefaultValuesWhenParameterNotProvided(true)
issueParams.assigneeId = project.leadUserName
issueParams.projectId = project.id
issueParams.reporterId = currentUser.name
issueParams.issueTypeId = issueTypes.find { it.name == 'Iteration Defect Resolution' }.id
issueParams.summary = "Iteration Defect Resolution created for ${sprintName} "

def sprintCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Sprint')[0]
issueParams.addCustomFieldValue(sprintCf.idAsLong, sprintId as String)
def sprintCreateCf = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName('Sprint Create Date')[0]
issueParams.addCustomFieldValue(sprintCreateCf.idAsLong, new Date().format('d/MMM/yyyy h:mm a'))

def validationResult = issueService.validateCreate(currentUser, issueParams)
if (validationResult.isValid()) {
def issue = issueService.create(currentUser, validationResult).issue
log.info "Issue created: $issue.key"
} else {
log.error validationResult.errorCollection
}
} finally {
jiraThreadLocalUtil.postCall(log)
}
}

This uses the preferred method for creating issue: issueService. This will respect permission checks and therefore you must make sure that the Sprint Create Date is on the create screen. But it also handles the indexing of the issue.

If you want to use the Sprint Start Date, then you must use the Sprint Started event.

how do I get the sprint name from only a certain project?

event.sprint.name get's the name of every sprint in all projects.
TAGS
AUG Leaders

Atlassian Community Events