query building with custom fields using JqlQueryBuilder

I have an existing builder as follows which is working in JIRA retriving issues.

JqlQueryBuilder builder = JqlQueryBuilder.newBuilder();

I have a custom field(id is 10000) that stores user object. Now I want to add this custom field to the builder object which is similar to assignee, reporter using or operator. How can i do that?

1 answer

1 accepted

try with this code

CustomField cf = customFieldManager.getCustomFieldObjectByName("CustomField Name");	
User cfValue=(User)issue.getCustomFieldValue(cf );	
JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder();
Query query = builder.customField(cf.getIdAsLong()).eq(cfValue.getName()).buildQuery();
SearchProvider searchProvider = ComponentAccessor.getComponentOfType(SearchProvider.class);
SearchResults searchResults = searchProvider.search(query, ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),PagerFilter.getUnlimitedFilter());
List<Issue> issues = searchResults.getIssues();

Thank you Prasad. With minor changes to your code, I am able to add JqlClauseBuilder to my JqlQueryBuilder object.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,042 views 13 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot