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
0 vote

created? updated? resolved?

@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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

356 views 0 6
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