Get issues of a porject by date

Hi, 

Could somebody translate my sentence in a groovy script? 

 

get issues of a project for a particular period? 

 

 

Thanks

5 answers

Hi Robi,

Not sure what you are trying to do here but you can get all issues between two dates in JQL using a query similar to below.

project = "Kristians Dev Project" and createdDate >= startOfMonth() and createdDate <= endOfMonth()

I hope this helps

Kristian

And in case you want  to use the - returned from a JQL issues - in a script

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter
 
def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponent(SearchService)
def jql = "project = 'Kristians Dev Project' and createdDate >= startOfMonth() and createdDate <= endOfMonth()"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issues = []
 
SearchService.ParseResult parseResult =  searchService.parseQuery(user, jql)
if (parseResult.isValid()) {
    def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
    issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) }
}
//an array with the issues returned from the JQL
return issues

created? updated? resolved?

due date

@Thanos Batagiannis [Adaptavist] 

Thanks!!! It works smile

I am getting all the issues of my JQL request. 

Now, can I sum all the values of a custom field from all the issues? 

 

 

 

issues.sum {it.getCustomValue(...)}

I have as result "No return value". 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.web.bean.PagerFilter

def issueManager = ComponentAccessor.getIssueManager()
def searchService = ComponentAccessor.getComponent(SearchService)
def jql = "project = 'AISC - Suivi des demandes' and ('Date de livraison' >= startOfMonth(-1) and 'Date de livraison' <=endOfMonth(-1))"
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def issues = []

SearchService.ParseResult parseResult = searchService.parseQuery(user, jql)
if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
// issues = searchResult.issues.collect { issueManager.getIssueObject(it.id) }
issues = issues.sum {it.getCustomValue("Temps d'intervention")}
}
//an array with the issues returned from the JQL
return issues

 

@Thanos Batagiannis [Adaptavist] 

@Jamie Echlin (Adaptavist)

 

Hello, 

 

I have found another script doing exactly the same thing, and the sum of spent time:

 

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.web.bean.PagerFilter

def jqlSearch = "project = 'AISC - Suivi des demandes' and ('Date de livraison' &gt;= startOfMonth(-1) and 'Date de livraison' &lt;=endOfMonth(-1))"
//If you are going to use a JIRA version =&gt; 7 then you should get the ApplicationUser instead of User, to do that remove the .directoryUser
def user = ComponentAccessor.getJiraAuthenticationContext().getUser().directoryUser
def searchService = ComponentAccessor.getComponentOfType(SearchService.class)
SearchService.ParseResult parseResult = searchService.parseQuery(user, jqlSearch)

def value = 0
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def myCustomField = customFieldManager.getCustomFieldObjectByName("Temps d'intervention")

if (parseResult.isValid()) {
try {
def results = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
def issues = results.getIssues()
issues.each {
if (it.getCustomFieldValue(myCustomField))
value += it.getCustomFieldValue(myCustomField).toInteger()

}
} catch (SearchException e) {
e.printStackTrace()
}
} else {
log.warn("Invalid query")
return null
}

return value

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,427 views 0 8
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