I'm trying to add 1 user as a watcher on a post function once a ticket is created. I'm using script runner and this is the syntax I currently have:
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def user = userManager.getUserByName("jhobson1")
if (issue.Components.equals("DART")){
watcherManager.startWatching(user, issue) }
Essentially if the components system field equals "DART" the user should be added as a watcher. Unfortunately, it doesn't do anything.
Thanks for any help.
It’s better to do this not in the post-function when creating, but as a listener, listening to the issue creation event.
Why: Because scripts tend to grow, new ones are added, as a result, issues begin to take a longer time to create, the entire service begins to slow down.
I wrote it for MyGroovy, but I think the principle is the same for Scriptrunner.
import com.atlassian.jira.component.ComponentAccessor
//issue = getIssue('TASK-1')
issue = event.issue
def component_id = 11111 //test component
if (issue.components.find{it.id == component_id}){
startWatching(getUserByName('username'), issue)
}
def getUserByName(String userName){
ComponentAccessor.userManager.getUserByName(userName)
}
def startWatching(user, issue){
ComponentAccessor.watcherManager.startWatching(user, issue)
}
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.