Forums

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

How to use JQL with java code

lamella
Contributor
March 14, 2022

Where can i find "get start" about JQL in java code? Just like "get start about JIRA plugin", I find docs about "JqlClauseBuilder", but i don't know how to use it, where can i find any "get start" or any "demo code"?

1 answer

1 accepted

0 votes
Answer accepted
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.
March 15, 2022

What do you mean by "get start" and why do you need any of it?

The API is pretty straight forward there.

(I'm using specific classes here, but remember that with groovy you can just use "def" and it will dynamically map variables without needing explicit class types.)

 

import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query

final String JQL_QUERY = "project = \"my project\" and issuetype = task"
final ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

JqlQueryParser jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
SearchService searchService = ComponentAccessor.getComponent(SearchService)

Query query = jqlQueryParser.parseQuery(JQL_QUERY)
SearchResults<Issue> searchResults = searchService.search(currentUser, query, PagerFilter.getUnlimitedFilter())

List<Issue> issues = searchResults.getResults()

for (Issue issue : issues) {
//do something per issue
}

 

Also take a look at Adaptavist Library: https://library.adaptavist.com/

It contains a lot of verified code with different use cases, so you can get an idea how to do something from them or where to start with the APIs since there are many managers/services to get somewhat familiar with.

lamella
Contributor
March 15, 2022

Hi Radek,

Thanks, in my plugin, I need to search all users in jira, I just know that i need to use JQL in servlet, but i don't know how to use it. I hadn't heard of this site before today, now I know.

Thanks again.

lamella
Contributor
March 15, 2022

The demo code you gave me is very helpful to me, thank you very much.

: )

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events