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.
Community moderators have prevented the ability to post new answers.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use the FieldConfigSchemeManager: call
List<FieldConfigScheme> getConfigSchemesForField(ConfigurableField field);
and then
FieldConfigScheme updateFieldConfigScheme(FieldConfigScheme newScheme, List<JiraContextNode> contexts, ConfigurableField field);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.