Can any one help me how to Add a custom field programmatically

Ankit Agarwal November 24, 2014

I want to add a customField(readonly textbox) programmatically

can it is possible in JIRA 

 

4 answers

1 vote
Udo Brand
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 24, 2014
Ankit Agarwal November 25, 2014

Thanks Nic Brough & Udo Brand can you please share the some links or any document to write the custom plugin for jira 1- automatically create the custom field and Associate the field to the appropriate screens

Udo Brand
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 25, 2014

For a plugin development you might start here: https://developer.atlassian.com/display/JIRADEV/JIRA+Plugin+Guide. However Jelly script can of course also add a field to a screen: https://confluence.atlassian.com/display/JIRA/Jelly+Tags#JellyTags-jira:AddFieldToScreen Since I have not developed a plugin by myself I'm not sure if it's worth the time unless you want to add custom fields frequently.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2014

I'd seriously reconsider the design here - is it *really* worth going through the process of researching and writing code for a plugin to add a couple of custom fields that you could just document for the end-user? If your argument is "but I need lots of custom fields", then I'd say that's a bad requirement - having lots of custom fields is a bad idea on many levels, and you probably need to re-evaluate it. (There is only one strong argument for "create custom field in a plugin" that I can think of, but I suspect it's not one you actually have)

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 27, 2014

Have you added the custom field to the screen?

0 votes
Ankit Agarwal November 26, 2014

Thanks Udo Brand & Nic Brough I am able to create as well Add custom field automatically using custom plugin code : Add in the atlassian-plugin.xml: <!-- import from the product container --> <component-import key="applicationProperties" interface="com.atlassian.sal.api.ApplicationProperties"/> <!-- Add custom field by java code --> <customfield-type key="admintextfield" name="Admin Editable Text Field" class="com.atlassian.jira.plugin.customfield.example.JiraCustomField"> <resource type="velocity" name="edit" location="templates/edit-jiraadminonlytext.vm"/> <description>Text field </description> </customfield-type> My edit-jiraadminonlytext.vm #controlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters.noHeader) <input type="textarea" name="$customField.id" value="$!value" /> #set ($displayValue = ${value}) #controlFooter ($action $fieldLayoutItem.fieldDescription $displayParameters.noHeader) My java Class File : JiraCustomField.java customFieldList = ComponentAccessor.getCustomFieldManager().createCustomField("MycustomField", "customField", field.getCustomFieldType(), field.getCustomFieldSearcher() ,null, field.getAssociatedIssueTypes()); Problem statement: Above code create a custom field (name = "MycustomField"). I am set the value of MycustomField at the time of issue creation but value of MycustomField is not shown in the bug screen Thanks in Advance

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 25, 2014

Depends on what you mean.  

You have phrased the question in a slightly ambiguous way (the wonders of the English language - even simple sentences can be immensely unclear).  

It sounds like you want to add a new custom field.  But a lot of people who ask that actually mean "How do I add data to a custom field", and that's a very different answer.

If you do really mean add a new custom field, then yes, of course you can, but you can only do it in a plugin that has direct access to the internals, or, as Udo has said, with a Jelly script.  You also need admin rights for the process you're running.  It's also not something you need to do often enough to justify coding it - almost every addon I know of that needs you to add custom fields simply puts "add custom field X" in the "How to install and use me" documentation.

If you do mean "set the data", then you've got a lot more options - Jelly and code in a plugin are still valid approaches, but you can also use REST, web hooks, external programs, tricks in the UI and and and...

Suggest an answer

Log in or Sign up to answer