Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get issues of a porject by date

Robi Anton
Contributor
April 8, 2016

Hi, 

Could somebody translate my sentence in a groovy script? 

 

get issues of a project for a particular period? 

 

 

Thanks

5 answers

0 votes
Robi Anton
Contributor
April 11, 2016

@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' >= startOfMonth(-1) and 'Date de livraison' <=endOfMonth(-1))"
//If you are going to use a JIRA version => 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
0 votes
Robi Anton
Contributor
April 10, 2016

@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? 

 

 

 

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2016
issues.sum {it.getCustomValue(...)}
Robi Anton
Contributor
April 10, 2016

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

 

0 votes
Robi Anton
Contributor
April 10, 2016

due date

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 10, 2016

created? updated? resolved?

0 votes
Kristian Walker _Adaptavist_
Community Champion
April 8, 2016

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 &gt;= startOfMonth() and createdDate &lt;= endOfMonth()

I hope this helps

Kristian

Thanos Batagiannis [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 8, 2016

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 &gt;= startOfMonth() and createdDate &lt;= 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events