Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

unable to add group as default watcher using Scriptrunner postfunction

Hi All, 

 

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

 Below is my code , However I am getting the below error

Cannot find matching method com.atlassian.jira.issue.watche.WatcherManger#startwatching(java.lang.object, com.atlassian.jira.issue.Mutableissue)

com.atlassian.jira.security.group.GroupManager#getGroupByName (jira.lang.string)

 

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 = ["groupname"]
watchUsers(grp)

3 answers

2 votes

Groups cannot be watchers, so the call is failing because you're trying to give the function data it does not handle.

0 votes

Hello @Shivani Chauhan

As Nic already shared that it's currently not possible to add groups as watchers. Please vote here for this feature request

https://jira.atlassian.com/browse/JRASERVER-12913

Hello @Shivani Chauhann
As @Nic Brough _Adaptavist_ said it is not possible right now, so the only possible way is to add to watchers all users in groups, if this satisfy requirement.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.security.groups.GroupManager

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

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

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,934 views 11 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you