How to use JQL querys in a scheduled service??

Pablo Gómez Justicia October 29, 2021

I am programming a service within a plugin. It is a service that is programmed in the administration for automatic execution. I need to do JQL queries from it, but 0 records are always retrieved.
If the same query is executed within another action, it does return results. From the service, the AO query and the retrieval of data from objects such as the issue, the project, the history, ... work well, but not the JQL queries.
Any idea to be able to carry out that query from here?

public class UpdateDaysInsStatusService extends AbstractService{

@Override
public ObjectConfiguration getObjectConfiguration() throws ObjectConfigurationException {
return getObjectConfiguration("UpdateDays", "services/updateDays.xml", null);
}

@Override
public void run() {
pruebajql("Backlog");
}

private void pruebajql (String estado) {
SearchService searchService = ComponentAccessor.getComponent(SearchService.class);
JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser();
builder.where().project("TKB").and().status(estado);

Query query = builder.buildQuery();
SearchResults<Issue> results;

try {
results = searchService.search(user, query, PagerFilter.getUnlimitedFilter());
System.out.println(" filas encontradas: " + results.getResults().size());

} catch (SearchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
}

 

1 answer

0 votes
Clark Everson
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 31, 2021

Hi Pablo,

Welcome to community!

I believe when working with this part of Jira you want to use SQL not JQL. JQL is for the graphical interface, not scripting, the database or the API.

Best,

Clark

Suggest an answer

Log in or Sign up to answer