It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How does one implement a custom field searcher based on an existing custom field searcher?

I have created a new issue field called "Business Driver" of field type "Labels". It works, but when I try to search for issues where has a specific value for "Business Driver", Jira instead searches the "Labels" field. This is a known issue, as per the Jira docs.

To get around this, I'm trying to create a new customfield-searcher to associate with the field. Since the functions are 99% the same as the existing "labelsearcher" customfield-searcher, I figured that I could pretty much clone the entry in system-customfieldtypes-plugin.xml and point the labelsearcher at a new customfield-searcher and avoid having to write a new Java class. Sadly, this seems to not be the case.

The original code for the label searcher is as such:

<customfield-searcher key="labelsearcher" name="Labels Searcher"
           i18n-name-key="admin.customfield.searcher.labels.name"
           class="com.atlassian.jira.issue.customfields.searchers.CustomFieldLabelsSearcher">
        <description key="admin.customfield.searcher.labels.desc">Search for values matching labels.</description>
        <resource type="velocity" name="label" location="templates/plugins/fields/view-searcher/label-searcher-label.vm"/>
        <resource type="velocity" name="search" location="templates/plugins/fields/edit-searcher/search-basictext.vm"/>
        <resource type="velocity" name="view" location="templates/plugins/fields/view-searcher/view-searcher-basictext.vm"/>

        <valid-customfield-type package="com.atlassian.jira.plugin.system.customfieldtypes" key="labels"/>
    </customfield-searcher>

My code is deeply similar. I've changed the key and the name in the hope of getting Jira to search the Business Driver field as if it was a label:

<customfield-searcher key="businessdriversearcher" name="Business Driver Searcher"
         i18n-name-key="admin.customfield.searcher.businessdriver.name"
         class="com.atlassian.jira.issue.customfields.searchers.CustomFieldLabelsSearcher">
     <description key="admin.customfield.searcher.businessdriver.desc">Search for values matching Business Driver.</description>
     <resource type="velocity" name="label" location="templates/plugins/fields/view-searcher/label-searcher-label.vm"/>
     <resource type="velocity" name="search" location="templates/plugins/fields/edit-searcher/search-basictext.vm"/>
     <resource type="velocity" name="view" location="templates/plugins/fields/view-searcher/view-searcher-basictext.vm"/>
     <valid-customfield-type package="com.atlassian.jira.plugin.system.customfieldtypes" key="labels"/>
</customfield-searcher>


The result is that in "Edit Custom Field Details" screen I have a new option for the Search Template for Business Driver. The new template is called "admin.customfield.searcher.businessdriver.name", which corresponds to the value of i18n-name-key. This leads me to believe that this is not quite as straightforward as I'd hoped. It would seem that either I need a new class that has 99% of the functions of the existing CustomFieldLabelsSearcher class, extend CustomFieldLabelsSearcher to search Business Driver, or update the package com.atlassian.jira.plugin.system.customfieldtypes to include a new key for my new field. All of these solutions seem really involved for what would seem to be a simple modification. Is there an easier way to do this? Am I making the problem more complex than it needs to be?

Note: I'm using Jira 4.2.2 standalone.

3 answers

I'm not familiar with searchers but you might want to look at some sample code if you have familiarity with Java and JIRA development.

Does you field have to be of "Labels" type? Can you use some other custom field type such as Select or multi select? Maybe that could make it easier as those kinds of fields will be searched separately from any other labels field.

Btw, If you remove "i18n-name-key", JIRA will probably show the "name" attribute.

Why dont just create a filter using jql?

"Business Driver" = "Your Search"

That would be the logical solution, yes, but it doesn't work. If you create a graph or a chart based on a JQL filter specifying "Business Driver", then try to bring up the list of issues generated by the chart I get the behavior described above. It's a long way to go for such a simple thing but I don't see a solution other than writing a custom searcher.

Still looking for an answer on this one. Any ideas?

What you did above was define a new searcher but it was still using the same Java class com.atlassian.jira.issue.customfields.searchers.CustomFieldLabelsSearcher so it was still doing the same (wrong) thing and searching only in the system Labels field.

Is there a known bug about this? That link was just to a docs page about labels.

~Matt

yup, just remove the i18n key. Also have a look at http://www.j-tricks.com/1/post/2010/09/custom-field-searchers.html for some tips.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in United States

Live! - Austin ACE -- Summer BASH 2019

Hey Austin! Come join us for our 2019 Atlassian Community Summer BASH as we transition ourselves into party status! Bring an attachment, log a great time, and collaborate with new friends as we celeb...

9 views 0 0
View post

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you