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

swetha meti January 30, 2017

 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 vote
Answer accepted
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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)
Shivani Chauhan September 30, 2018

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 1, 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.

Shivani Chauhan October 1, 2018

Hi @Tarun Sapra,

 

Thank you for the response. I have posted a new question. Could you kindly help us on that.

https://community.atlassian.com/t5/Jira-Core-questions/unable-to-add-group-as-default-watcher-using-Scriptrunner/qaq-p/904056

0 votes
taher shili May 24, 2017

anyone can poste the right code ?

0 votes
swetha meti January 31, 2017

Any update on this?

Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2017

Have you tried updated version of my code?

swetha meti January 31, 2017

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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. 

swetha meti January 31, 2017

Hi,

 

Getting the below error

 

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

 

 

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

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2017

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

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2017

please see my complete code answer

swetha meti January 31, 2017

Thanks a lot!!, its working fine.

0 votes
swetha meti January 31, 2017

Getting the below error after removing ComponentAccessor.getInstance()






0 votes
swetha meti January 31, 2017

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 31, 2017

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

swetha meti January 31, 2017

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

swetha meti January 31, 2017

Any update on this?

 

0 votes
swetha meti January 30, 2017

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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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

0 votes
Vasiliy Zverev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 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 Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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.

0 votes
Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 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

Suggest an answer

Log in or Sign up to answer