Programmatically Create Select Type Custom Field In Jira
Author
October 3, 2016
In order to create a custom field type, you should be aware of basic plugin development.
Please follow the following steps to create an advanced custom field type in Jira.
- Create a basic Jira plugin skeleton. For creating Jira Plugin please refer to the given link https://developer.atlassian.com/docs/getting-started/set-up-the-atlassian-plugin-sdk-and-build-a-project/create-a-helloworld-plugin-projectAfter creating a Basic plugin skeleton modify your atlassian-plugin.xml and add the following code in your atlassian-plugin.xml.
- After creating a Basic plugin skeleton modify your atlassian-plugin.xml and add the following code in your atlassian-plugin.xml. <customfield-type key=”Jira-Cf-Type-field” name=”Jira-Select CFType” class=”com.atlassian.jira.plugin.customfield.JiraCustomFieldType”><description>Create Your Own Advance Custom Field Type</description> <resource type=”velocity” name=”view” location=”templates/plugins/fields/view/view-basictext.vm”/><resource type=”velocity” name=”edit” location=”templates/edit- jiraselectcftype.vm”/><resource type=”velocity” name=”xml” location=”templates/plugins/fields/xml/xml-basictext.vm”/></customfield-type>
com.atlassian.jira.plugin.customfield.JiraCustomFieldType“ class which extends an available CustomField Class to provide an entry point for the custom field.
Resources Represent the various vm files which are executed for rendering the field. - In order to create the custom field type, first you have to create the class representing the field.JiraCustomFieldType.javapackage com.atlassian.jira.plugin.customfield;import java.util.HashMap;import java.util.Map;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.customfields.impl.SelectCFType;
import com.atlassian.jira.issue.customfields.manager.GenericConfigManager;
import com.atlassian.jira.issue.customfields.manager.OptionsManager;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.customfields.option.Options;
import com.atlassian.jira.issue.customfields.persistence.CustomFieldValuePersister;
import com.atlassian.jira.issue.customfields.view.CustomFieldParams;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.fields.layout.field.FieldLayoutItem;
import com.atlassian.jira.issue.fields.rest.json.beans.JiraBaseUrls;
import com.atlassian.jira.issue.search.SearchContextImpl;
import com.atlassian.jira.util.ErrorCollection;
public class JiraCustomFieldType extends SelectCFType {
private final OptionsManager optionsManager;
public JiraCustomFieldType(CustomFieldValuePersister customFieldValuePersister,
OptionsManager optionsManager,
GenericConfigManager genericConfigManager,
JiraBaseUrls jiraBaseUrls) {
super(customFieldValuePersister, optionsManager, genericConfigManager, jiraBaseUrls);
this.optionsManager=optionsManager;
}
@Override
@SuppressWarnings(“unchecked”)
public Map getVelocityParameters(Issue issue, CustomField field,
FieldLayoutItem fieldLayoutItem) {
Map parameters = super.getVelocityParameters(issue, field, fieldLayoutItem);
FieldConfig fieldConfig = null;
if(issue == null)
{
fieldConfig = field.getReleventConfig(new SearchContextImpl());
System.out.println(“=========fieldConfig if” + fieldConfig);
} else
{
fieldConfig = field.getRelevantConfig(issue);
System.out.println(“======fieldConfig else” + fieldConfig);
}
Options options = this.optionsManager.getOptions(fieldConfig);
if (options.isEmpty()) {
this.optionsManager.createOption(fieldConfig, null, new Long(1), “Option-One”);
this.optionsManager.createOption(fieldConfig, null, new Long(2), “Option-Two”);
}
options = this.optionsManager.getOptions(fieldConfig);
Map<Long, String> results = new HashMap<Long, String>();
Long selectedId= (long) -1;
boolean selected = false;
Object value = field.getValue(issue);
System.out.println(“== value” + value);
if (value!=null) {
selected=true;
}
for (Option option : (Iterable<Option>) options) {
results.put(option.getOptionId(), option.getValue());
if (selected && value.toString().equals(option.getValue())) {
selectedId = option.getOptionId();
System.out.println(“selectedId======== : “ +selectedId);
}
}
System.out.println(“==results== : “ +results);
parameters.put(“results”, results);
parameters.put(“selectedId”, selectedId);
return parameters;
}
} - Create a template to render the field on issue screen.templates/edit- jiraselectcftype.vm#* @vtlvariable name=”results” type=”java.util.Map” *##* @vtlvariable name=”selectedId” type=”java.lang.String” *##controlHeader ($action $customField.id $customField.name $fieldLayoutItem.required $displayParameters.noHeader)<head>$webResourceManager.requireResource(“com.atlassian.auiplugin:aui-select2”)
</head>
<select name=”$customField.id” id=”$customField.id” class=”select”>
<option value=””>Select</option>
#foreach ($mapEntry in $results.entrySet())
#if ( $selectedId == $mapEntry.key )
<option selected=”selected” value=”$mapEntry.key”>$mapEntry.value</option>
#else
<option value=”$mapEntry.key”>$mapEntry.value</option>
#end
#end
</select> - After creating your class and template compile your code and go to the browser and access your local Jira.
- How to check your custom field in Jira?
Pranshu Goyal, Director of Products at Mirekta, states: “We envision DSM to be used by every small to a medium-sized organization dealing with bad data and want to get rid of duplicates easily with no cost. We have faced issues dealing with duplicates in our organization. That inspired us to make a solution that is not only simple to use but can be used widely to make the organization’s data clean to make them more efficient and productive. We want DSM to be a solution for every organization looking for duplicate management capability better than the Salesforce out-of-the-box solution with no additional cost.”
Recent Posts
-
Leveraging AI to Enhance Sales Effectiveness13 Mar 2025 Use-case
-
Revolutionizing Manufacturing with AI: Predictive Maintenance, Supply Chain Optimization, and More11 Mar 2025 E-Book
-
NetSuite for Manufacturing: Streamlining Operations and Solving Key Challenges07 Mar 2025 Blog
-
How to Build Your First Agent in Salesforce Agentforce24 Feb 2025 Blog
-
ERP vs Salesforce Revenue Cloud: Which One is Right for Your Business?24 Feb 2025 E-Book
-
Revolutionizing Manufacturing with Salesforce: A Playbook for Efficiency & Growth18 Feb 2025 E-Book
-
Salesforce 2025 Game-Changing Trends You Need to Know28 Jan 2025 Blog
-
Agentforce 2.0: Everything You Need to Know About the Latest Update22 Jan 2025 Blog
-
The Ultimate Guide to NetSuite Development: Tools and Techniques10 Jan 2025 Blog
-
How Salesforce Nonprofit Cloud Transforms Fundraising Strategies10 Jan 2025 Blog
Categories
Featured by



