The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

How can I output only the first issue?

Max Mustermann
Contributor
November 4, 2022

Several issues are printed with this code. But how can I output only the first or only the second issue?

SearchResult searchResult =
restClient.getSearchClient().searchJql(
"project = \"<project>\" AND status = \"open\"" ,
5,
1,
Sets.newHashSet("*all")).
claim();

System.out.println(searchResult.getIssues());

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

1 vote
70
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!
November 4, 2022

It looks like it is returning a list, so perhaps you can index the value are looking for.  Example:

For the first issue:

System.out.println(searchResult.getIssues()[0]); 

 

For the second issue:

System.out.println(searchResult.getIssues()[1]);

 

Alternatively you could make the code a bit more clear and add one more line:

issueToPrint = searchResult.getIssues()[0];

System.out.prntln(issueToPrint);
Radek Dostál
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 Champions.
November 4, 2022

In case it returns an empty list (no issues), then you want to make sure it is not empty first, e.g.

List<Issue> issues = searchResult.getIssues()
Issue firstIssue = !issues.isEmpty() ? issues.get(0) : null

 

But otherwise you cannot limit issue results with JQL. You can do it with REST, but with JQL the closest you get to is by limiting it with the query itself, e.g. "created > startOfWeek()" or something similar, there is no result limit property.

TAGS
AUG Leaders

Atlassian Community Events