Get a list of watchers from an issue

dean ashton January 22, 2014
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.IssueWatcherAccessor
import com.atlassian.jira.issue.watchers.WatcherManager

ComponentManager componentManager = ComponentManager.getInstance()
Issue issue = componentManager.getIssueManager().getIssueObject("EPIC-10")
User user = componentManager.getJiraAuthenticationContext().getLoggedInUser()
String recipient = ''
try {

    //Add comment to the original
    CommentManager commentManager = componentManager.getComponentInstanceOfType(CommentManager.class)

    def list = issue.getCustomFieldValue(componentManager.getCustomFieldManager().getCustomFieldObject("customfield_12117"))

    for (u in list) {
        if (recipient == ''){
            recipient = u.displayName
        }  else {
            recipient = recipient + ', ' + u.displayName
        }
    }
    IssueWatcherAccessor iwa = ComponentAccessor.getComponent(IssueWatcherAccessor.class)
    list =  iwa.getWatchers(issue, java.util.Locale)

    for (u in list){
        if (recipient == ''){
            recipient = u.displayName
        }  else {
            recipient = recipient + ', ' + u.displayName
        }
    }

    //   String comment = 'Epic has been sent to: ' + recipient + ' for approval.'
    //   commentManager.create(issue, user.getName(), comment, true)

    return 'For Approval Email has been sent to: ' + recipient + ' for approval.'
} catch(all) {
    return false
}

Returns error message...

javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.watchers.DefaultIssueWatcherAccessor.getWatchers() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl, java.lang.Class) values: [EPIC-10, class java.util.Locale] Possible solutions: getWatchers(com.atlassian.jira.issue.Issue, java.util.Locale), getWatcherKeys(com.atlassian.jira.issue.Issue)

1 answer

1 accepted

2 votes
Answer accepted
Peter Van de Voorde
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 22, 2014

Hi Dean,

You should be given an instance of the java.util.Locale class as an argument in the method iwa.getWatchers(issue,...) .

Something like this :

Locale en = new Locale("en");

iwa.getWatchers(issue,en);

It's actually pretty clearly explained in the error message.

Best regards,

Peter

dean ashton January 22, 2014

Thanks Peter - for some reason I completly missed that!

Kyle Moseley _blueridge_cx_ September 16, 2014

Peter, do you know why I would receive this error? Stack Trace: javax.script.ScriptException: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getWatchersFor() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [SAND-1] Possible solutions: getWatches() . . . Caused by: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getWatchersFor() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [SAND-1] Possible solutions: getWatches() . . . Caused by: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.IssueImpl.getWatchersFor() is applicable for argument types: (com.atlassian.jira.issue.IssueImpl) values: [SAND-1] Possible solutions: getWatches()

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events