create custom field for any issue type

Dragica Soldo October 31, 2013

Hi,

I am creating a custom field in a plugin and trying to add a custom field searcher for it , both on plugin installation.

On creating custom field I would like it to be availavle for all issue types and I'm getting them like following:

List<GenericValue> issueTypes = new ArrayList<GenericValue>();
...
Collection<IssueType> list = constantsManager.getAllIssueTypeObjects();
for (IssueType issueType : list) {
	issueTypes.add(issueType.getGenericValue());
}
...
try {
	CustomField cf = customFieldManager.createCustomField(name, "", selectFieldType, fieldTypeSearcher,
	contextTypes, issueTypes);

	return cf;
} catch (GenericEntityException e) {
	return null;
}

Indeed after plugin is installed under custom field configuration part I see that each issue type (except for story) is selected, but I would like "any issue type" to be selected instead. Unfortunately searcher is not set for the custom field and I have to set it under 'custom field edit'. After that when I try to search by custom field it is hidden before I select exact issue type in the search.

And when I configure it manually for "Any issue type" then it's not hidden even if I don't select any other criteria.

Does anybody know

1. How can I make "Any issue type" selected on custom field configuration from java code, instead of each type selected?

2. Is it possible to set searcher for the custom field from java, so I don't have to do it manually after plugin installation? I have managed to do this from a class registered in atlassian-plugin.xml webwork action, but it's not working from class registered under <component.../> When I try to do it in the same way, as customFieldManager.getCustomFieldSearcher(typeKey), I'm getting InvocationTargetException in second (<component...>) case

Appreciate any help,

Dragica

1 answer

1 accepted

1 vote
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.
October 31, 2013

1. You have to add null.

//Create a list of issue types for which the custom field needs to be available
        List&lt;GenericValue&gt; issueTypes = new ArrayList&lt;GenericValue&gt;();
        issueTypes.add(null);

2. You can pass the key directly.

See http://www.j-tricks.com/1/post/2012/03/plugin-lifecycle-events.html for both. It shows creation of custom field with a searcher.

Dragica Soldo October 31, 2013

Hi,

Thank you very much for your quick answer.

I'm not quite clear what I was doing wrong for the second question, since I have tried this before and was getting InvocationTargetException . Maybe implementing the first fix influenced the second as well.

Anyways, I have implemented both changes and they works excelent!

Thanks again :) ,

Dragica

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events