Cannot find matching method com.atlassian.jira.ComponentManager#getWatcherManager()

 We are using Groovy script  as a post function during the create transition and it errors as below

 

package com.onresolve.jira.groovy.canned.workflow.postfunctions

 

import com.atlassian.jira.ComponentManager

 

def componentManager = ComponentManager.getInstance()

def watcherManager = componentManager.getWatcherManager()

def userManager = componentManager.getUserUtil()

 

def watchUsers = {usernames ->

   usernames.each {

         def user = userManager.getUser(it)

         watcherManager.startWatching(user, issue.getGenericValue())

      }

}

//Users can be added and removed from this list below. Make sure the names are in quotes and are comma separated.

//   def users = 

 

Error as below

 

  • Script68.groovy:6 [Static type checking] - Cannot find matching method com.atlassian.jira.ComponentManager#getWatcherManager(). Please check if the declared type is right and if the method exists. @ line 6, column 22.
  • Script68.groovy:7 [Static type checking] - Cannot find matching method com.atlassian.jira.ComponentManager#getUserUtil(). Please check if the declared type is right and if the method exists. @ line 7, column 19.
  • Script68.groovy:11 [Static type checking] - Cannot find matching method java.lang.Object#getUser(java.lang.Object). Please check if the declared type is right and if the method exists. Possible solutions: getAt(java.lang.String) @ line 11, column 21.
  • Script68.groovy:12 [Static type checking] - Cannot find matching method java.lang.Object#startWatching(java.lang.Object, org.ofbiz.core.entity.GenericValue). Please check if the declared type is right and if the method exists. @ line 12, column 10.
  • Script68.groovy:12 Use the Data object getters instead. Since v5.0. @ line 12, column 45.
  • Script68.groovy:12 Use the Data object getters instead. Since v5.0. @ line 12, column 45.

Can anyone assist on this? We have JIRA v7.1.10.

8 answers

1 accepted

1 votes
Tarun Sapra Community Champion Jan 31, 2017

Complete code

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.util.UserManager
 
WatcherManager watcherManager = ComponentAccessor.getWatcherManager()
UserManager userManager = ComponentAccessor.getUserManager()
 
def watchUsers = {usernames ->
    usernames.each {     
        watcherManager.startWatching(userManager.getUserByName((String)it), issue)
    }
}

def users = ["lli", "skaravadi"]
watchUsers(users)
0 votes
Tarun Sapra Community Champion Jan 30, 2017

The error is coming because your using the wrong class, instead of ComponentManager please use ComponentAccessor

https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/ComponentManager.html - ComponentManager doesn't have the methods you need in latest JIRA API Docs 

While ComponentAccessor has all the methods which you are using like (getWatcherManager()) - https://developer.atlassian.com/static/javadoc/jira/latest/reference/com/atlassian/jira/component/ComponentAccessor.html

Here is refactored version. Try this one. It is not clear for me where watchUsers variable is initialised, but it should work better:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.util.UserManager

WatcherManager watcherManager = ComponentAccessor.getWatcherManager()
UserManager userManager = componentManager.getUserUtil()

def watchUsers = {usernames ->
    usernames.each {      
        watcherManager.startWatching(userManager.getUserByName(it), issue)
    }
}
Tarun Sapra Community Champion Jan 31, 2017

"UserManager userManager = componentManager.getUserUtil()"


UserUtil can't be assigned to instance of UserManager and componentManger needs to be replaced by ComponentAccessor.

Here is more one:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.util.UserManager

WatcherManager watcherManager = ComponentAccessor.getWatcherManager()
UserManager userManager = ComponentAccessor.getUserUtil()

def watchUsers = {usernames ->
    usernames.each {
        watcherManager.startWatching(userManager.getUserByName(it), issue)
    }
}
Tarun Sapra Community Champion Jan 31, 2017

This again won't work as this statement is wrong

UserManager userManager = ComponentAccessor.getUserUtil()

I have the provided the correct answer and has been accepted  "Complete code" please see that for correct code.

getting the below error when i replaced import com.atlassian.jira.ComponentManager to import com.atlassian.jira.component.ComponentAccessor and ComponentManager.method to ComponentAccessor.method

 

image2017-1-31 16:22:41.png

Tarun Sapra Community Champion Jan 30, 2017

remove the line - ComponentAccessor.getInstance() it's not required. As all the getter methods in the ComponentAccessor class are static thus call them directly like

ComponentAccessor.getWatcherManager()
ComponentAccessor.getUserManager()

etc

Below is the complete script

 

package com.onresolve.jira.groovy.canned.workflow.postfunctions

 

import com.atlassian.jira.component.ComponentAccessor

 

def componentManager = ComponentAccessor.getInstance()

def watcherManager = ComponentAccessor.getWatcherManager()

def userManager = ComponentAccessor.getUserUtil()

 

def watchUsers = {usernames ->

   usernames.each {

         def user = userManager.getUser(it)

         watcherManager.startWatching(user, issue.getGenericValue())

      }

}

//Users can be added and removed from this list below. Make sure the names are in quotes and are comma separated.

   def users = ["lli", "skaravadi"]

   watchUsers(users)

Tarun Sapra Community Champion Jan 31, 2017

Nice!!
Please accept / upvote the answers provided by users who helped you come up with the answer. Thanks.

Still facing issues.Below are the error messages.Could you advice?

Any update on this?

 

Getting the below error after removing ComponentAccessor.getInstance()






Any update on this?

Have you tried updated version of my code?

Yes, i did try and i am getting the below error

 

image2017-2-1 14:24:10.png

 

 

image2017-2-1 14:24:38.png

Tarun Sapra Community Champion Jan 31, 2017

As I have mentioned in my answer that componentManager is not used anymore and instead ComponentAccessor.

 

Instead of "componentManager.getUserUtil()" it should be

ComponentAccessor.getUserUtil()

@vasiliy  There is a typo in your answer. 

Hi,

 

Getting the below error

 

image2017-2-1 14:41:6.png

 

 

image2017-2-1 14:41:34.png

Tarun Sapra Community Champion Jan 31, 2017

you need to Cast it to string - like (String)it

Tarun Sapra Community Champion Jan 31, 2017

please see my complete code answer

Thanks a lot!!, its working fine.

anyone can poste the right code ?

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Thursday in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

480 views 1 15
Read article

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