Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Groovy script to display all the issues in a given Jira project based given issue type

Ramesh Penuballi December 8, 2022

Dear All,

 

I am writing a script to display all the issues which are of "Story" issue type in a given project "ABC" but my script is listing all the issues in a project but not getting the list based on the requested issue type.

 

Below is the script to get the list of issues in given project.

Method-1:

*************

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.config.manager.IssueTypeSchemeManager
import com.atlassian.jira.project.Project

IssueTypeSchemeManager issueTypeSchemeManager = ComponentAccessor.getIssueTypeSchemeManager()

//issueTypeSchemeManager.getAllSchemes()*.name.

Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("ABC")
def issueTypeMgr = ComponentAccessor.getIssueManager()
def availissuetypeslist = issueTypeSchemeManager.getIssueTypesForProject(project)*.name
def issuetype = "Story"
long count = issueTypeMgr.getIssueCountForProject (project.id)
if (issuetype in availissuetypeslist)
{ def issue = issueTypeMgr.getIssueObjects(issueTypeMgr.getIssueIdsForProject(project.id))
}

Method-2:

***************

import org.ofbiz.core.entity.GenericValue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
def ret=[]
ProjectManager projectManager = ComponentAccessor.getProjectManager()
Project proj= projectManager.getProjectByCurrentKey("ABC")
IssueManager issueManager = ComponentAccessor.getIssueManager()
for (GenericValue issueValue: issueManager.getProjectIssues(proj.genericValue))
{
Issue issue = issueManager.getIssueObject(issueValue.id)
ret.add issue
}
return ret
In both the methods i am getting all the issues in the project ABC and tried all the combinations in the script runner server version (7.6) version but no result.
we are running the 8.13.9 server version of Jira and really looking forward the help to display the list of issues based on the required issue type  from "ABC" Jira project.
Thanks and Regards,
Ramesh

1 comment

Comment

Log in or Sign up to comment
Peter-Dave Sheehan
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.
December 8, 2022

I think you will have better and more performant results if you use the IssueSearchService with a JQL query.

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

SearchService searchService = ComponentAccessor.getComponent(SearchService)
ApplicationUser user = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def jql = 'Project = ABC and type=Story'
def jqlParseResult = searchService.parseQuery(user, jql)
assert jqlParseResult.isValid(), jqlParseResult.errors
def issueCount = searchService.searchCount(user, jqlParseResult.query) as Integer
log.info "$issueCount issues were found with jql=\"$jql\""
def listOfIssues = searchService.search(user, jqlParseResult.query, PagerFilter.unlimitedFilter).results
Like # people like this
Ramesh Penuballi December 8, 2022

Thanks for Peter for your quick help and you saved me..... The script ran fine and and displays the only stories from the given project.

The result looks like below in the list format.. 

DocumentIssueImpl[issueKey=ABC-1234], DocumentIssueImpl[issueKey=ABC-2124],DocumentIssueImpl[issueKey=ABC-4212].

Not sure if we can avoid  "DocumentIssueImpl from the result and to display 3 to 4 issues per row.

 

Thanks and Regards,

Ramesh Penuballi

Peter-Dave Sheehan
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.
December 9, 2022

I'm not sure what you are doing this with a script.

You could just search for issues using the UI and export the list.

But if you want to output the listOfIssues in a more friendly way, you can add 

return listOfIssues.collect{it.issueKey} //print one long comma separated list
//or
return listOfIssues.collect{it.issueKey}.join('<br>') //print each issue key on a separate line

If you really want to print 3/4 per line, you'll have to come up with your own algorithm for processing the list. There is nothing built-in to groovy to do that as far as I'm aware.

Like # people like this
Ramesh Penuballi December 13, 2022

Hi Peter,

Thanks for the sharing the details. I will have a look and update  the script accordingly.My script is working as expected..

Once again thanks alot for providing the valuable suggestion.

Thanks,

Ramesh

TAGS
AUG Leaders

Atlassian Community Events