It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

unable to resolve class com.atlassian.jira.ComponentManager

Just upgraded to Jira 8.1.0 with Adaptavist ScriptRunner for JIRA 5.5.3.1-jira8

Suddenly our ScriptRunner Listeners are failing 100% of time with the following in the logs...

2019-04-10 11:11:16,957 http-nio-80-exec-18 ERROR gstegall 671x20674x1 18lp2y7 10.7.202.3 /secure/QuickEditIssue.jspa [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
Script123.groovy: 1: unable to resolve class com.atlassian.jira.ComponentManager
2019-04-10 11:11:28,066 http-nio-80-exec-52 ERROR cpfeifer_aa 671x20732x1 10xp4ga 10.7.202.3 /secure/AssignIssue.jspa [c.o.scriptrunner.runner.AbstractScriptListener]

 

When I bring up the script in the editor, it also reports a syntax error on the very first import line for above component. 

Has anyone else experienced this issue?

4 answers

1 accepted

1 vote
Answer accepted

ComponentManager has been deprecated since JIRA 7.11, which is the reason that you cannot resolve this class any longer.

You should migrate to using ComponentAccessor instead, and you may see the API documentation for this class here:

https://docs.atlassian.com/software/jira/docs/api/7.11.0/com/atlassian/jira/component/ComponentAccessor.html

If you have a specific example that uses ComponentManager, feel free to post it here and I'll be happy to show you how you can change it to use ComponentAccessor instead.

How come when I try to import like this....
import com.atlassian.jira.component.ComponentAccessor

it tells me unable to resolve class com.atlassian.jira.component.ComponentAccessor?

Like Siddesh Mahajan likes this

Here's a script I'm trying to use to convert tasks to sub-tasks but it implements the compoenentManager class. Could you convert it to use the ComponentAccessor?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.UpdateIssueRequest;

//Examples, 5 is my subtask issue type id. Will be different for others. Can find it in the issue history tab after converting a task to a sub-task
changeToSubTaskAndLink("XXX-8889", "XXX-0000", "5")

//Method to do all the work
def changeToSubTaskAndLink(parentId, childId, subTaskIssueTypeId)
{
//Get the parent Issue
def parent = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId)
//Get the child Issue
def child = ComponentManager.getInstance().getIssueManager().getIssueObject(childId)
//Change the child to the subtask type
child.setIssueTypeId(subTaskIssueTypeId)
//Update the issue
ComponentAccessor.getIssueManager().updateIssue((ApplicationUser)ComponentManager.getInstance().jiraAuthenticationContext?.user,
(MutableIssue)child,
UpdateIssueRequest.builder().build())
//Create the subtask link, if this is not done you'll end up with orphans
ComponentAccessor.getSubTaskManager().createSubTaskIssueLink(parent,
child,
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser())
}

I have a script that uses ComponentManager and needs to be converted to use ComponentAccessor instead.

 

// Script to consolidate values from multiple fields to a single field
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Logger
import org.apache.log4j.Level

// Enable logging
def log = Logger.getLogger("com.jira.copyfieldcontent")
log.setLevel(Level.DEBUG)

// Managers
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def authContext = ComponentAccessor.getJiraAuthenticationContext();

// CustomField ID's
String FieldOneID = "customfield_10603"
String FieldTwoID = "customfield_10403"
String FieldThreeID = "customfield_13346"
String FieldFourID = "customfield_10601"

// DEBUG
//def issue = issueManager.getIssueByCurrentKey("SB-1")


// FieldOne
CustomField FieldOne = customFieldManager.getCustomFieldObject(FieldOneID)
String FieldOneValue = issue.getCustomFieldValue(FieldOne)
log.debug("FieldOneValue:" + FieldOneValue)

// FieldTwo
CustomField FieldTwo = customFieldManager.getCustomFieldObject(FieldTwoID)
String FieldTwoValue = issue.getCustomFieldValue(FieldTwo)
log.debug("FieldTwoValue:" + FieldTwoValue)

// Cascading Select Field
String FieldFourParent = ""
String FieldFourChild = ""
CustomField FieldFour = customFieldManager.getCustomFieldObject(FieldFourID)
Map FieldFourValue = issue.getCustomFieldValue(FieldFour) as Map
if (FieldFourValue) {
FieldFourParent = FieldFourValue.get(null)
FieldFourChild = FieldFourValue.get("1")
}

// Store in description
//String description = "FieldOneValue: " + FieldOneValue + "\n" + "FieldTwoValue: " + FieldTwoValue
//issue.description = description

// Store in FieldThree
String description = ""
description = description + "FieldOneValue: " + FieldOneValue + "\n"
description = description + "FieldTwoValue: " + FieldTwoValue + "\n"
description = description + "FieldFourParent: " + FieldFourParent + ", FieldFourChild: " + FieldFourChild +"\n"

log.debug("Description:" + description)
CustomField FieldThree = customFieldManager.getCustomFieldObject(FieldThreeID)
issue.setCustomFieldValue(FieldThree, description)
issueManager.updateIssue(authContext.getLoggedInUser(),issue, EventDispatchOption.DO_NOT_DISPATCH,false)

 

Can you please have a look at it?

Best Regards

Daniel Miks 

Hello @Daniel Miks,

I saw that the script you posted imports com.atlassian.jira.ComponentManager, but I do not see where the ComponentManager is being used.

After migrating to Jira 8.0, this script will no longer function as the ComponentManager class has been removed. However, all that is needed to change in this script is to remove the import of the component manager. Take care that you don't confuse the ComponentManager class with other managers:

// Managers
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def authContext = ComponentAccessor.getJiraAuthenticationContext();

The above are not using the ComponentManager class - they are separate interfaces, accessed via ComponentAccessor. The ComponentManager class was historically used to access the manager interfaces like so:

ComponentManager componentManager = ComponentManager.getInstance();
delegator = (DelegatorInterface) componentManager.getComponentInstanceOfType(DelegatorInterface.class);

If you would like to make this a separate question so that others can benefit from this answer, you're welcome to do so and I can answer any further questions you have under that post. 

Like # people like this

Hi @Ross McCoy and thank you for your answer.

Hi @Ross McCoy and other guys.

Please help with my short script that add comment in transition:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commmgr.create(issue, currentUser, "comment text", true)
issue.store()

Thanks 

self-fix ;)

import com.atlassian.jira.component.ComponentAccessor

def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
def commentManager = ComponentAccessor.getCommentManager()
def user = jiraAuthenticationContext.getLoggedInUser()

commentManager.create(
issue,
user,
"comment text",
false)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

boolean status = false

IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField myCustomField1 = customFieldManager.getCustomFieldObjectByName("TestLead")
CustomField myCustomField2 = customFieldManager.getCustomFieldObjectByName("DesignLead")
String myCustomFieldVal1 = (String) issue.getCustomFieldValue(myCustomField1)
String myCustomFieldVal2 = (String) issue.getCustomFieldValue(myCustomField2)
if(myCustomFieldVal1.equals("Yes") && myCustomFieldVal2.equals("Yes"){
status = true
}
)
return status

 Can you please help me convert this. 

 

Thanks

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

347 views 1 3
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you