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 .
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
how do I get the sprint name from only a certain project?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.