Forums

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

ComponentManager to ComponentAccessor

MM B November 2, 2021

Just upgraded JIRA v.8.16.1 and ScriptRunner 6.37.0. I read that ComponentManager is deprecated and now I have to refactor this using by ComponentAccessor. But, I got "static type checking - the variable [issueManager] is undeclared." error.  I am very unfamiliar with this language. Can you please help to convert it by using ComponentAccessor?

Below, I try to explain changes.

//BEFORE

//issueManager = ComponentManager.getInstance().getIssueManager();

//AFTER

issueManager = ComponentAccessor.getIssueManager();

void createSubtask(String issueType) {

..

//below line shows an error. static type checking - the variable [issueManager] is undeclared.

subTask = issueManager.createIssueObject(authenticationContext.getLoggedInUser(), issueObject);

}

 

1 answer

1 accepted

0 votes
Answer accepted
Dirk Ronsmans
Community Champion
November 2, 2021

Hi @MM B ,

That makes sense since you did set the variable issueManager but you didn't tell it what it is. Maybe you also commented that out?

A quick fix would be to do a 

def issueManager = ComponentAccessor.getIssueManager();

def is basically a catchall and you can put all types of objects in it. It will restrict you from getting type-ahead/checks but it will catch any type you put in to it.

MM B November 2, 2021

Hi @Dirk Ronsmans,

Thank you for your quick response.

Yes, you're right. I accidentally skipped the "def" while typing it here. Original code is as follows. I marked bold the line causing the error. Static type checking error happens, when I use the issueManager in the createSubtask method.

//BEFORE

//issueManager = ComponentManager.getInstance().getIssueManager();

//AFTER

def issueManager = ComponentAccessor.getIssueManager();

void createSubtask(String issueType) {

..

//below line throws an error. static type checking - the variable [issueManager] is undeclared.

subTask = issueManager.createIssueObject(authenticationContext.getLoggedInUser(), issueObject);

}
Dirk Ronsmans
Community Champion
November 2, 2021

But does it actually error out? Cause if you don't put a specific type but "def" then it doesn't really know what it is and it will throw some warnings.

The code however will execute without an issue.

Suggest an answer

Log in or Sign up to answer