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

Accepted Answer
1 vote
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)

Hi @Tarun Sapra,

Thank you for the code, this worked perfectly for adding users as default watchers. However I am struggling while trying to add group as default watcher. 

 

Could you please let me know if it is possible to add group as default watcher?

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.util.GroupManager
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.bc.group.search.GroupPickerSearchServiceImpl
import java.lang.String

WatcherManager watcherManager = ComponentAccessor.getWatcherManager()
GroupManager groupManager = ComponentAccessor.getGroupManager()

def watchUsers = {groupnames ->;
groupnames.each {
watcherManager.startWatching(groupManager.getGroupByName((String)it), issue)
}
}

def grp = ["GrpTGJiraConfluenceSupport"]
watchUsers(grp)


Tarun Sapra Community Champion Oct 01, 2018

Hello @Shivani Chauhan

Can you please create a separate question for this, as replying on an old thread which already has an solved question would create confusion for the 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

0 votes
Vasiliy Zverev Community Champion Jan 30, 2017

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.

Vasiliy Zverev Community Champion Jan 31, 2017

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?

Vasiliy Zverev Community Champion Jan 31, 2017

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 Sign up to answer
Community showcase
Published yesterday in Jira Ops

Jira Ops Early Access Program Update #2: Let’s talk severity levels

Welcome to your weekly Jira Ops Early access program update, where we’re sharing news and updates on Jira Ops' progress as we work toward our 1.0 release. If you ever want to drop us feedback or idea...

31 views 0 0
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