JqlQueryBuilder searching customfield

Pascal Müller April 4, 2012

Hi JIRA devs

I have a problem with searching jira issue from a plugin. It's about the following code:

final JqlQueryBuilder jql = JqlQueryBuilder.newBuilder();

String projectkey = "PROJECT";
long cfkey = 10300L;
String uid = "abcd1234";

Query query = where().project(projectkey).and().customField(cfkey).eq(uid).buildQuery;

SearchProvider searchProvider = COMPONENT_MANAGER.getSearchProvider();
SearchResults results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter());

So this query returns an empty result set. I tried several things. Also this

Query query = where().project(projectkey).and().customField(cfkey).notEq(uid).buildQuery();

Which should actually return all the other issue in the project.

I also tried without project, just the customfield search.

And the funny thing is, this even does not work for the fields "description" and "environment" either. The user has the rights to see these issues. Selecting just the project works like a charm:

Query query = where().project(projectkey).buildQuery();

I think, something goes really wrong here. Somebody has a guess?

2 answers

1 accepted

2 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
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.
April 4, 2012

eq cannot be used with text fields. Use like. But be aware that it is equilent to "contains" in JQL. So the results will have everything matching to the text you passed.

0 votes
Pascal Müller April 4, 2012

Ok, it's obviously not possible to compare two strings like this.

jql.where().project(projectkey).and().customField(cfkey).eq(uid).buildQuery;

So, the way to go is to use "like" instead

jql.where().project(projectkey).and().customField(cfkey).like(uid).buildQuery;

I think this could be a quite common mistake? For me, my understanding of "like" in a not facebook but a String context is usually: "Meier" == "Meyer" => true

Suggest an answer

Log in or Sign up to answer