Forums

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

How can I retrieve all issues/issue keys for a project?

Rohan Weston
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 10, 2018

Hi there,

 

I'm pushing data into Jira from other sources.

 

I need to have the ability to check if an issue (identified by the issue key) already exists, and if it does then I don't want to override it.

 

The issue here (pardon the pun) is that I know the project name and key, but I don't know the individual issue Id's. The API only allows you to retrieve an issue by ID, as opposed to a list. I need to pull all of them down within the scope of a project.

 

Please advise? Thanks in advance.

1 answer

0 votes
Alexey Matveev
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.
July 10, 2018

Hello,

It would be like this:

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.web.bean.PagerFilter;


def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.user
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)

def query = jqlQueryParser.parseQuery(jqlQuery)
def results = searchProvider.search(query, user, PagerFilter.unlimitedFilter)
results.issues.collect
{ issue -> issueManager.getIssueObject(issue.id) }
}

def user = ComponentAccessor.jiraAuthenticationContext.user
def jqlQuery = "project = \"projectkey\""
def issues = findIssues(jqlQuery)
issues.each{it -> 

// your code

}
Abhipsa Mohapatra March 5, 2019

@Alexey Matveev 

Please help me with my below code. I need the functionality mentioned in "//" in bold

------------------------------------------------

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.fields.config.FieldConfig
import com.atlassian.jira.issue.context.IssueContextImpl
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.customfields.option.Option
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import org.apache.log4j.Logger
import org.apache.log4j.Level
import com.atlassian.jira.issue.MutableIssue

log.setLevel(Level.DEBUG)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def query = jqlQueryParser.parseQuery(jqlQuery)
def results = searchProvider.search(query, user, PagerFilter.unlimitedFilter)
results.issues.collect {
issue -> issueManager.getIssueObject(issue.id)
}
}

def results = "issueFunction in linkedIssuesOf('issuetype = Epic', 'is epic of') AND resolution = Unresolved"

String customFieldName = "Cross Stream List"
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(customFieldName)
def issues = findIssues(results)

for (childissue in issues)
{
// First get handle of the Parent Object of childissue
// Then i want to set the Custom field "Cross Stream List" of Parent as same as Child issue.
}

Alexey Matveev
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.
March 5, 2019

Suggest an answer

Log in or Sign up to answer