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

How to programatically create CustomField ?

Pawel M June 6, 2016

Hi,

I am trying to create checkbox, label and textfield custom fields programatically in Java. I have found the following API in CustomFieldManager:


public CustomField createCustomField(
	String fieldName,
	String description,
	CustomFieldType fieldType,
	CustomFieldSearcher customFieldSearcher,
	List<JiraContextNode> contexts,
	List<IssueType> issueTypes) throws GenericEntityException;



customFieldManager.createCustomField(
	"My funny fieldName",
	"My funny fieldName description",	
     ?, //how to create the specified object ???
     ?, //how to create the specified object ???
     ? //how to create the specified object ???
);

 

But I have no idea how to create fields marked with "?"
Can you give me some examples how to do it? I would be very grateful.


 
 

 

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Petar Petrov (Appfire)
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.
June 6, 2016

See the last part to my previous comment - In case you need specific context - use theIssueTypeManager to acquire IssueType instances and CustomFieldUtils.buildJiraIssueContexts() to construct JiraContextNode instances.
Then use the following code to create the context:

FieldConfigScheme newConfigScheme = new FieldConfigScheme.Builder()
.setName("name").setDescription("description")
.setFieldId(customFieldId).toFieldConfigScheme();
FieldConfigScheme scheme = ComponentAccessor.getComponent(FieldConfigSchemeManager.class)
.createFieldConfigScheme(newConfigScheme, contexts, issueTypes, field);

 

To create an option use the com.atlassian.jira.issue.customfields.manager.OptionsManager:

ComponentAccessor.getComponent(OptionsManager.class)
.createOption(scheme.getOneAndOnlyConfig(), null, 0l, optionValue);

See the javadoc of OptionsManager for more details on the different parameters.

Mind that some of the parameters may vary depending on the JIRA version - the code above is for JIRA 7.x

2 votes
Petar Petrov (Appfire)
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.
June 6, 2016

Use the CustomFieldManager instance to get the appropriate type and searcher:

customFieldManager.getCustomFieldType("com.atlassian.jira.plugin.system.customfieldtypes:url");
customFieldManager.getCustomFieldSearcher("com.atlassian.jira.plugin.system.customfieldtypes:exacttextsearcher");

You need to know the type id and searcher ids. For the last two parameters which define the custom field context you can just pass null (for global context). In case you need specific context - use the IssueTypeManager to acquire IssueType instances and CustomFieldUtils.buildJiraIssueContexts() to construct JiraContextNode instances.

0 votes
Pawel M June 12, 2016

Hi,
Is it possible to get the "Default Configuration Scheme" for my custom field associated with contexts and issueTypes instead of creating the new field configuration scheme?

The code below:

customField = customFieldManager.createCustomField(name, description, customFieldType, customFieldSearcher, jiraContextNodes, issueTypeList);

call the method:

fieldConfigSchemeManager.createDefaultScheme(customField, contexts, issueTypes);


I would like to edit the "Default Configuration Scheme" for my custom field instead of creating and modifying the new configuration scheme.

Petar Petrov (Appfire)
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.
June 13, 2016

Use the FieldConfigSchemeManager: call 

List<FieldConfigScheme> getConfigSchemesForField(ConfigurableField field);

and then 

FieldConfigScheme updateFieldConfigScheme(FieldConfigScheme newScheme, List<JiraContextNode> contexts, ConfigurableField field);
0 votes
Pawel M June 6, 2016

No, putting null in contexts parameter (4th parameter)

customFieldManager.createCustomField(name, description, customFieldType, customFieldSearcher, null, null);

result in "Not configured for any context". So I am thinking how to create Global Context.
I think that this method will be useful to create global context:

CustomFieldUtils.buildJiraIssueContexts(true, null, null);


The second question is  how to add values and options to radio buttons and checkboxes programatically in java. See the picture below.


 image2016-6-7 9:43:1.png

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events