Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Howto run a JQL inside groovy script

Dirk Bromberg
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.
May 27, 2015

Hi,

I want to run a JQL query to fetch some issues inside a groovy script an then doing something (adding a comment) on the issues from the result. Is there a current 6.4.x running codesample?

Regards,

Dirk

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Tomasz Stec
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.
May 27, 2015

Hi,

Yes, latest version of Script Runner works on JIRA 6.4.x.
To fetch issues using JQL i woluld recommend to look into JIRA API. Basically you can do it with code like this:

import com.atlassian.jira.jql.builder.JqlQueryBuilder;
import com.atlassian.jira.issue.search.SearchException;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.issue.search.SearchResults;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.jql.builder.JqlClauseBuilder;
import com.atlassian.jira.issue.Issue;
import com.atlassian.crowd.embedded.api.User;
JqlQueryBuilder jqlBuilder = JqlQueryBuilder.newBuilder();
List<Issue> issueList = new ArrayList<Issue>();
JqlClauseBuilder clauseBuilder = JqlQueryBuilder.newClauseBuilder();
clauseBuilder.customField(10107L).like("some string");

SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class);
CustomFieldManager cfManager = ComponentAccessor.getCustomFieldManager();
CustomField myCF = cfManager.getCustomFieldObject(10003L);
User user = ComponentAccessor.getUserUtil().getUserByKey("userKey").getDirectoryUser();
//OR cfManager.getCustomFieldObjectByName("My custom field name");

jqlBuilder.where().status().notEq("Closed").and().status().notEq("Resolved").and().customField(myCF.getIdAsLong()).isNotEmpty().and().addClause(clauseBuilder.buildClause());
try {
final SearchResults results = searchProvider.searchOverrideSecurity(jqlBuilder.buildQuery(), user, PagerFilter.getUnlimitedFilter(), null);
issueList = results.getIssues();
}catch(SearchException e){
    e.printStackTrace();
}
Dirk Bromberg
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.
May 27, 2015

Is there a way to change from jqlBuilder.where().status().no .... to a Method / Factory which takes the origin JQL String to Object-Model?

Tomasz Stec
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.
May 28, 2015

I am not aware of such method...

JamieA
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.
May 28, 2015

> can you explain what you mean by: to a Method / Factory which takes the origin JQL String to Object-Model?

JamieA
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.
May 28, 2015

If it means what I think you mean then JqlQueryParser does that.

JamieA
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.
May 28, 2015
0 votes
Dirk Bromberg
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.
May 31, 2015

SearchService sserv = ComponentAccessor.getComponentOfType(SearchService.class); ParseResult parseQuery = sserv .parseQuery(user,"MY JQL");

TAGS
AUG Leaders

Atlassian Community Events