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

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 Leaders.
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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events