How to search for Issues based on CustomField

JIRA Documentation

Index

This example is tested in JIRA 3.6.5. It searches issues which match the search term of a given CustomField.

User you = ((JiraAuthenticationContext) ComponentManager.getComponentInstanceOfType(JiraAuthenticationContext.class)).getUser();
SearchProvider sProvider = (SearchProvider) ComponentManager.getComponentInstanceOfType(SearchProvider.class);
SearchRequest sRequest = new SearchRequest(you);

CustomFieldManager cfm = ComponentManager.getInstance().getCustomFieldManager();
CustomField cf = cfm.getCustomFieldObject("customfield_10021");
IssueSearcher searcher = cf.getCustomFieldSearcher();
FieldValuesHolder fvh = new FieldValuesHolderImpl();
CustomFieldParams cfp = new CustomFieldParamsImpl();
List list = new ArrayList();
list.add("hello");
cfp.put(null, list);
cfp.setCustomField(cf);
fvh.put("customfield_10021", cfp);
searcher.populateSearchRequest(sRequest, fvh);

List searched = sProvider.search(sRequest, you, PagerFilter.getUnlimitedFilter()).getIssues();

See also: How to search for Issues from within a Plugin

Labels

faq_jira_dev faq_jira_dev Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Dec 12, 2007

    Joshua Goodall says:

    If you know the parameters that the searcher uses, then this simplifies to (for ...

    If you know the parameters that the searcher uses, then this simplifies to (for example, a Resolution Date CF from the Charting plugin):

     
    sRequest.addParameter(new AbsoluteDateRangeParameter("customfield_10090", startDate, endDate));
    

    Those in possession of the Java source of JIRA will find the hint of which parameter to use inside the populateSearchRequest of the relevant searcher class.

    To discover the relevant searcher class, peek inside the customfield's XML descriptor - the class attribute of the customfield-searcher element. You'll find that in system-customfieldtypes-plugin.xml for the JIRA distribution, or the atlassian-plugin.xml inside a plugins jarfile.