Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

unable to add group as default watcher using Scriptrunner postfunction

Shivani Chauhan October 1, 2018

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
Nic Brough -Adaptavist-
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.
October 1, 2018

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

0 votes
Mark Markov
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.
October 1, 2018

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)
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.
October 1, 2018 edited

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

Suggest an answer

Log in or Sign up to answer