Given the context, let me make a huge assumption - You know how to create a skeleton plugin! If not, go to here and do it before you continue!
For the example, I chose to create a Read Only customfield that stores the last edited user name! It is simple in functionality and enough to explain the basic concepts.
So here we go:
Modify the atlassin-plugin.xml to inclue the customfield module as follows. You will define the custom field class and the related velocity templates here!
The next important thing is the velocity templates. You can define different or same templates for each functionalities. In this case, I have chosen to use the same for view, column-view and xml. view template is used in the 'View Issue' page, column-view template in 'Issue Navigator' & reports and xml in XML exports. For edit, I have chosen a different template as you can see there.
Let's have a look at the class!
Now, you need to populate the velocity context with the variables you need. For that, all you need to do is to override the 'getVelocityParameters' method. This returns you a Map with lots of populated params and you can add additional key-value pairs into it as I have added 'currentUser'
Note: As you can see, 'authcontext' is already in there and I don't need an extra variable to be put in there as I can retieve the current user in the vm from this variable. I have done this just for the sake of the tutorial!
Now let's move no to the templates. The variables in the context is shared across all the templates. Let us have a look at the edit template.
Note: $authContext.user.name will give you the same result as $currentUser
That is it for edit template. View templates looks like this:
And now, we have our custom field ready!! Package it and deploy it into jira-home/plugins/installed-plugins (WEB-INF/lib if you created plugin-1 version). And see if it works
If you need searching enabled, you need to tie it up with a JIRA's built in Searcher or one you have written! More of that and more about custom fields plugins be found here. And more on CustomFields here. Njoy!
Finf the full source code below. And feel free to post your comments/feedback!