Script fail - Assigning multiple watchers with Scriptrunner post function

Ashley March 1, 2023

Hello! I have this script, but it isn't assigning the watchers when it goes through the "create issue" transition. I was hoping to assign these people as watchers for this specific issue type we have. What might be wrong with it? I'm not strong at scripting, at all...so this is all pretty foreign to me. Thank you for your help!

import com.atlassian.jira.component.ComponentAccessor

def issueTypeWatchers = [
'Spares and Repair Parts': ['DG1459', 'BK8615','MS9025'],
]

issueTypeWatchers[issue.issueType.name].each{userName->
def user = userManager.getUserByName(userName)
def watcherManager = ComponentAccessor.getWatcherManager()

}

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Reece Lander _ScriptRunner - The Adaptavist Group_
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.
March 6, 2023

Hey Ashley,

You should be able to achieve this easily with our new HAPI feature, introduced in ScriptRunner for Jira 7.11.0

 

def issueTypeWatchers = [
'Task' : ['task-watcher-a', 'task-watcher-b']
].withDefault { [] }

issueTypeWatchers[issue.issueType.name].each {
watcher ->
issue.addWatcher(watcher)
}

 
You will need to move the ScriptRunner post function down to the bottom of the list.

 

For more information on HAPI, see the following links:

 

Cheers :)

Reece Lander _ScriptRunner - The Adaptavist Group_
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.
March 6, 2023

The values here are usernames, not user keys by the way.

Ashley March 8, 2023

Thank you! I'll give that a try!

TAGS
AUG Leaders

Atlassian Community Events