Forums

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

Script to add multiple users as a watchers for a specific issue-type on ticket creation - Server

Theresa Reynolds January 28, 2021

I need a script for a post function to add mutliple users as watchers of a specific issue type when ticket created.  I am currently on Server version of Jira but  moving to Data Center, so I need script for both environments. 

1 answer

1 accepted

0 votes
Answer accepted
PD Sheehan
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.
January 28, 2021

Hi @Theresa Reynolds 

I will be in the same migration boat for Server to DC and my understanding is that most scriptrunner standard script implementations will be identical between the two environments.

Most jira admin would agree with the philosophy of avoiding setting other users as watchers. Invariably, someone will come around to ask why they were added as a watcher to a ticket which they did not want to watch.

You can achieve similar notification objectives by adjusting your notification scheme using a specific role.

But that being said, I know notifications can't be issue type-specific, and there are cases where this standard philosophy can justifiably be overruled.

A script like this may work for you

import com.atlassian.jira.component.ComponentAccessor

def issueTypeWatchers = [
'Bug': ['user1','user2'],
'Story': ['user2', 'user3']

]
issueTypeWatchers[issue.issueType.name].each{userName->
def user=ComponentAccessor.userManager.getUserByName(userName)
user && ComponentAccessor.watcherManager.startWatching(watcher, issue)
//user && ... will ensure that the user was valid before attempting to add as watcher
}

 Put this as a custom post-function script at the end of all the post functions.

Suggest an answer

Log in or Sign up to answer