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

How can I use a custom-field type that I defined in atlassian-plugin.xml in another module?

Markus_COGNITIFF
Contributor
August 3, 2019
As per documentation, I am creating a new custom field type in atlassian-plugin.xml using the SDK CLI. Now I want to use that new custom field type and create a custom field in another module when the plugin is enabled. However, that module is throwing null pointer exceptions, because the new type is not yet available. The class implementing the type is not annotated as a component - it only gets scanned by spring. It appears the class is instantiated by Jira some time after the plugin has been enabled. How do I know when it is safe to use the new type?

2 answers

1 accepted

0 votes
Answer accepted
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 3, 2019

Rather then creating custom field via module you can create event listener for you Custom Field Type PluginModule or whole Plugin and create field when you receive that event.

You can find Java doc for plugins related event in this.

https://docs.atlassian.com/DAC/javadoc/plugins/2.5/reference/packages.html

0 votes
Markus_COGNITIFF
Contributor
August 4, 2019

Thanks for the suggestion. Unfortunately, the custom field type is still not available even after the 'module enabled' event is emitted. As you can see in the logs, the custom-field-type class gets instantiated after the module is enabled. So first 1) plugin is enabled and then 2) module is enabled only then 3) the custom field gets created (which oddly gets triggered by visiting the custom field page in the browser).

2019-08-04 11:48:32,353 QuickReload - Plugin Installer INFO      [atlassian.plugin.manager.PluginEnabler] Plugin 'hk.com.epictechnology.plugins.wsjf-plugin' is now ENABLED
2019-08-04 11:48:32,356 QuickReload - Plugin Installer INFO [com.epictechnology.plugins.IssueCreatedResolvedListener] Module enabled with this key: wsjf-custom-field
2019-08-04 11:50:05,472 http-nio-2990-exec-4 INFO admin 710x11818x1 g6fxpq 0:0:0:0:0:0:0:1 /secure/admin/ViewCustomFields.jspa [com.epictechnology.plugins.WsjfCustomField] WsjfCustomField class instantiated (logged by constructor).

 

I am so baffled... Is there some other event I can listen to? I tried PluginModuleAvailableEvent, but that doesn't get emitted at all. 

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 4, 2019

Have you tried

public void afterPropertiesSet() throws Exception

In you plugin life cycle listener class.

Markus_COGNITIFF
Contributor
August 8, 2019

That worked! I ended up having to use an async event because the custom-field-type module had an issue with reentrancy. Thanks for your help! 

Suggest an answer

Log in or Sign up to answer