Hello,
I use JIRA 5.2.11 and I need to set a group of watchers each time an issue is created. I plan on using workflow and a post function to accomplish this. This is my first groovy script so I'm a newbie. I have cobbled together code and have eliminated some of the errors but now I'm down to:
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.user.util.DefaultUserManager.getUser() is applicable for argument types: (com.atlassian.jira.crowd.embedded.ofbiz.OfBizUser) values: [mkttest:1] Possible solutions: getUser(java.lang.String), getUsers(), getAllUsers(), getAt(java.lang.String)
which I can't seem to get rid of. Any insights would be helpful. Note that right now, I'm just hard coding the issue number to see if I can get it to work.
Thanks!
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.Issue
def userManager = ComponentAccessor.getUserManager()
def groupManager = ComponentAccessor.getGroupManager()
def issueManager = ComponentAccessor.getIssueManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def group = userManager.getGroup("jira-watcher-list")
def watchUsers = groupManager.getUsersInGroup(group).each
{
def user = userManager.getUser(it)
def issue = issueManager.getIssueObject("TST-2")
watcherManager.startWatching(user, issue)
}
watchUsers(group)
Thanks to both of you for you inputs.
I was able to get it to work by doing the following:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.crowd.embedded.api.Group
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.issue.Issue
def userManager = ComponentAccessor.getUserManager()
def groupManager = ComponentAccessor.getGroupManager()
def issueManager = ComponentAccessor.getIssueManager()
def watcherManager = ComponentAccessor.getWatcherManager()
groupManager.getUsersInGroup("jira-watcher-list").each {
def issue = issueManager.getIssueObject("TST-2")
watcherManager.startWatching(it, issue)
}
Now, I'm not sure if it's the best way to code it - but it works! :-) Thanks again for your help!
that's a happy thing to hear it is working. But I have a doubt that you require this functionality for only issue with key TST-2?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
True - but my proof of concept is working so now I can generize it! Thanks again!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Clare,
You can try this Java statement by converting into groovy script and may be it work.
ComponentAccessor.getWatcherManager().startWatching(ComponentAccessor.getUserManager().getUserByKey(it), issue);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You are almost there... from a quick look at your code I would say use:
def watchUsers = groupManager.getUsersInGroup(group).each
{
def issue = issueManager.getIssueObject("TST-2")
watcherManager.startWatching(it, issue)
}
Because getUsersInGroup returns a a collection of User.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the suggestion. I tried that and now I get:
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: java.util.ArrayList.call() is applicable for argument types: (com.atlassian.crowd.embedded.impl.ImmutableGroup) values: [com.atlassian.crowd.embedded.impl.ImmutableGroup@d1ac903f] Possible solutions: tail(), wait(), any(), max(), last(), wait(long)
Any other thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your closure is wrong. Try this:
import com.atlassian.jira.component.ComponentAccessor def userManager = ComponentAccessor.getUserManager() def groupManager = ComponentAccessor.getGroupManager() def issueManager = ComponentAccessor.getIssueManager() def watcherManager = ComponentAccessor.getWatcherManager() def group = userManager.getGroup("jira-watcher-list") groupManager.getUsersInGroup(group).each { def issue = issueManager.getIssueObject("TST-2") watcherManager.startWatching(it, issue) }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.