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

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

Logan G Hawkes
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.
October 12, 2011

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
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.
November 13, 2011

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.

0 votes
Mikael Löwenadler
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.
November 13, 2011

Why dont just create a filter using jql?

"Business Driver" = "Your Search"

Logan G Hawkes
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.
November 14, 2011

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.

Logan G Hawkes
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.
December 6, 2011

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

MattS
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.
December 8, 2011

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

0 votes
Muzaffer Ozakca November 13, 2011

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.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events