Get FieldConfigManager from ComponentAccessor

I am writing a REST plugin . I need FieldConfigManager from ComponentAccessor.

Is this possible or i have to use jira api?

6 answers

1 accepted

1 votes

Try this.

FieldConfigManager fieldConfigManager = ComponentAccessor.getComponent(FieldConfigManager.class)

Now I am getting error

ComponentAccessor has not been initialised.

You are writing a Java plugin, right? Are you sure you are not trying to inject ComponentAccessor anywhere?

can you share your code so we can check what is wrong!!

Doing it this way in my SpringBoot application I always get an exception that the ComponentAccessor is not initialized.

  

ComponentAccessor has not been initialised.

 

Can anybody tell me what I have to do that the ComponentAccessor will be properly initialized in a SpringBoot environment? Finally, I want to access the CustomFieldManager to work upon CustomFields...

 ...

customfieldMap.forEach((k, v) -> {
CustomFieldManager cfm = ComponentAccessor.getComponent(CustomFieldManager.class);
CustomField cf = cfm.getCustomFieldObjectByName(k);
System.out.println(cf.getValue((com.atlassian.jira.issue.Issue)v));
...
}
...

 

I get this exception even when I explicitely autowire the ComponentAccessor with 

 private ComponentAccessor componentAccessor;

public void setComponentAccessor(final ComponentAccessor componentAccessor) {
    this.componentAccessor = componentAccessor;
}

...but the ComponentAccessor should be accessed in a static way anyway, shouldn't it!?

yes i am not injecting anywhere

yes i am not injecting anywhere

import com.atlassian.jira.component.ComponentAccessor;

if (fieldConfigId != null)
{
FieldConfigManager fieldConfigManager = ComponentAccessor.getComponent(FieldConfigManager.class);
fieldConfig = fieldConfigManager.getFieldConfig(fieldConfigId);
}

can you try with this

FieldConfigManager fieldConfigManager = ComponentAccessor.getOSGiComponentInstanceOfType(FieldConfigManager.class)

I tried ComponentAccessor.getComponentOfType same error

i have update my anser can you try with that!!

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,799 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot