Get a list of watchers from an issue

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

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

Thanks Peter - for some reason I completly missed that!

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

182 views 0 5
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