JIRA 7.12.x Changing issue type scheme programatically

Hey Guys

I’m trying to change the issue type scheme of a project programatically using a atlassian plugin sdk with a rest module, we are trying to execute the below code section and we are getting exception (on run-time) Unable to resolve component: interface com.atlassian.jira.web.action.admin.issuetypes.ManageableOptionType

Also note this code perfectly works for jira server 7.2.x same is failing for 7.12.x

FieldConfigSchemeManager fieldConfigSchemeManager = ComponentAccessor.getFieldConfigSchemeManager();
ProjectManager projectManager = ComponentAccessor.getProjectManager();

FieldConfigScheme fieldConfigScheme = fieldConfigSchemeManager.getFieldConfigScheme(newIssueTypeSchemeId);
Project project = projectManager.getProjectObjByKey(projectKey);

//get already associated projects and add ours to that list and update
List<Project> alreadyAssociatedProjects = new ArrayList<Project>();
alreadyAssociatedProjects.addAll(fieldConfigScheme.getAssociatedProjectObjects());
alreadyAssociatedProjects.add(project);

Long[] projectIds = new Long[alreadyAssociatedProjects.size()];
int count = 0;
for (Project iteredProject : alreadyAssociatedProjects) {
    projectIds[count++] = iteredProject.getId();
}
List<JiraContextNode> contexts = CustomFieldUtils.buildJiraIssueContexts(false, projectIds, projectManager);

ManageableOptionType manageableOptionType = ComponentAccessor.getComponent(ManageableOptionType.class);
FieldManager fieldManager = ComponentAccessor.getFieldManager();
ConfigurableField configurableField = fieldManager.getConfigurableField(manageableOptionType.getFieldId());

//Remove the existing association
fieldConfigSchemeManager.removeSchemeAssociation(contexts, configurableField);

fieldConfigSchemeManager.updateFieldConfigScheme(fieldConfigScheme, contexts, configurableField);
log.info(projectKey + " IssueTypeScheme changed to id : " + issueTypeSchemeBean.getId());
return Response.ok(new SchemeBean(String.valueOf(fieldConfigScheme.getId()), fieldConfigScheme.getName(),
        fieldConfigScheme.getDescription())).build();

Appreciate any thoughts of how to get this done

Thanks!

Hi Pasan,

I’m relatively new to Jira development myself, so my following comment might be flawed or not respecting some other related things:

For what I’m doing, I ended up not using the manageableOptionType at all because using a field of type CustomField was also working, enabling me to get rid of that dependency. As I only have to deal with custom fields, this is good enough for me. I guess you want to do more than that?

Hi @pasan, thanks for highlighting the versions as that information is valuable.

Checking the ManageableOptionType java docs for v7.12.3, there are already two classes that implement ManageableOptionType as compared to v7.2.3’s only one. This leads to an error that looks something like

<no-component> needs a 'com.atlassian.jira.web.action.admin.issuetypes.ManageableOptionType' injected via '<unknown>', but there are too many choices to inject. These:[ConstructorInjector-class com.atlassian.jira.web.action.admin.issuetypes.IssueTypeManageableOption, ConstructorInjector-class com.atlassian.jira.web.action.admin.priorities.PriorityManageableOption]

Since you’re more interested with IssueTypeManageableOption, can you try getting the component IssueTypeManageableOption directly if it works for you? Something like

ManageableOptionType manageableOptionType = ComponentAccessor.getComponent(IssueTypeManageableOption.class);

Cheers,
Ian

1 Like

Hello,

I can’t understand one hting… why
FieldConfigScheme fieldConfigScheme = fieldConfigSchemeManager.getFieldConfigScheme(newIssueTypeSchemeId);

don’t bring FieldConfigScheme but Issue type schemes

And what more important how to actually get and update FieldConfigScheme of project.

You can do it for example this way:

FieldConfigScheme fieldConfigScheme = prioritySchemeManager.getScheme(projectManager.getProjectObj(projectId));