Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Add new context while creating a new project

Chandan Gupta
Contributor
September 10, 2018

How can I create a new context for a custom field while creating a new project via project template.??

1 answer

0 votes
Alexey Matveev
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.
September 10, 2018

Hello,

Just go to cog item -> Issues -> Custom fields. Find the required custom field and go to the configuration screen. Then you can add a new context.

You can find more info here:

https://confluence.atlassian.com/adminjiraserver071/configuring-a-custom-field-802592532.html

go to the adding new context part.

Chandan Gupta
Contributor
September 10, 2018

Thanks Alexey, But I was looking for doing it programatically.

I am doing the following thing

/*********************************************************************/

/* CUSTOM CONTEXT*/

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
FieldConfigSchemeManager fieldConfigSchemeManager = ComponentAccessor.getFieldConfigSchemeManager();
FieldManager fieldManager = ComponentAccessor.getFieldManager();

ArrayList<CustomField> customFields = new ArrayList<>();
customFields.add(customFieldManager.getCustomFieldObject(10504L));
ProjectContext newProjectContext = new ProjectContext(project.getId());

for (CustomField customField : customFields) {

/** It will fetch all the configuration scheme available on custom field **/
List<FieldConfigScheme> fieldConfigSchemes = customField.getConfigurationSchemes();

String configName = project.getKey() + ": Configuration scheme for " + project.getName();
String description = ": Configuration scheme for " + project.getName();

FieldConfigScheme firstScheme = fieldConfigSchemes.get(0);
FieldConfigScheme configScheme = new FieldConfigScheme.Builder()
.setName(configName)
.setDescription(description).toFieldConfigScheme();

List<JiraContextNode> existingSchemes = firstScheme.getContexts();
JiraContextNode newContextNode = newProjectContext;
List<JiraContextNode> updatedSchemes = new ArrayList<>();
for (JiraContextNode scheme : existingSchemes) {
updatedSchemes.add(scheme);
}
updatedSchemes.add(newContextNode);
List<IssueType> list = new ArrayList<>(firstScheme.getAssociatedIssueTypes());
fieldConfigSchemeManager.createFieldConfigScheme(configScheme, updatedSchemes,list ,customField);
}
fieldManager.refresh();

 

/****************************************************************/

I am able to create new config scheme. But now I am trying to copy the options from default config scheme to new config scheme

Keri
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 20, 2018

Hi Chandan, 

 

We also have a dedicated Developer Community that might be good to check out for development related questions. Since the topics are more focused, it's easier for other developers to watch the questions coming in and provide guidance.

 

This might be useful, not just for this question, but for all your recent Community posts. 

 

If you've figured out the answer, please let us know if you can to help others who might run into similar problems!

 

Cheers, 

Keri

Suggest an answer

Log in or Sign up to answer