Add Project roles as watchers in issue

Rita YOUNES [Infosysta]
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.
April 4, 2016

Hi , 

I have a project role called developers, Once an issue created I want that the user of this project role te be watchers for this issues.

 

@Kristian Walker (Adaptavist) Kindly advice.

 

 

 

6 answers

1 accepted

1 vote
Answer accepted
Thanos Batagiannis _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.
April 6, 2016

Hey Rita

You can create a custom listener, assign it to listen for issue create events and in the inline script 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.security.roles.ProjectRoleManager

Issue issue = event.issue
def watcherManager = ComponentAccessor.getWatcherManager()
def projectRoleManager =ComponentAccessor.getComponent(ProjectRoleManager)
def developersProjectRole = projectRoleManager.getProjectRole("Developers")
def actorsInRole = projectRoleManager.getProjectRoleActors(developersProjectRole, issue.getProjectObject())

actorsInRole.getApplicationUsers().each {user ->
    watcherManager.startWatching(user, issue)
}

For more information have a look in WatcherManager and ProjectRoleManager

PS. Is tested in a JIRA v7.1 , I don't expect to be different in a 6.* JIRA version. 

Ushma Mulwani November 24, 2020

is there any syntax change required as of today ?

image.png

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 6, 2016

Hi Rita,

Apologies for not getting back to you sooner but I have been busy with other items this week.

I have tested the code that my colleague Thanos has provided below and can confirm that this is the solution that you should use.

I have enclosed some steps below on how you can add this as listener into JIRA.

  1. Click the Administration cog in the top right hand corner of JIRA and select Add Ons from the drop down menu.
  2. On the page that is displayed locate and click on the Script Listeners link on the left hand side of the page.
  3. On the page that is displayed click on the Custom Listener link.
  4. In the Project Key box select the projects that this listener is supposed to work on.
  5. In the events box select Issue Created
  6. In the Inline Script box paste the code provided by Thanos Below.
  7. Your screen should look similar to the screenshot below.
    image2016-4-7 10:35:3.png
  8. Click the Add button to save the listener.

I hope this helps.

Kristian

0 votes
Rita YOUNES [Infosysta]
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.
April 5, 2016

@Jamie Echlin (Adaptavist) I want to write a script that only some groups have this features.

 do you have any idea on how to do it  through script runner?

0 votes
Mike Friedrich
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.
April 5, 2016

This is a build-in feature. No plugin needed. Just add a new role in System Administration in section Security - Roles, add a new role, e.g. "Global Watcher". Then in your project's Notification Scheme add this role to all notifications you need.

Sorry, this does not make them "issue-watchers" (not added to issue field value Watchers for each issue), they just receive all email, which may be what you want or not.

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 5, 2016

Hi Rita,

I think you may find the Add Watcher listener provided by ScriptRunner will be useful to resolve this requirement.

The official documentation on the Add Watcher listener can be viewed here.

I hope this helps

Thanks

Kristian

Rita YOUNES [Infosysta]
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.
April 5, 2016

Hi @Kristian Walker (Adaptavist) in fact I want to use the project role instead of the current user. I dont know how to do it using the listener

 

awaiting your advise.

Thanks

Rita

0 votes
JamieA
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.
April 5, 2016

What have you got so far?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events