Grrovy Scirpt to add user to Watcher List

Pushparaj Bhaskaran July 9, 2013

HI,

Using the below script to add an user to watcher list using Script runner in the issue Create PostFunction

import com.atlassian.jira.ComponentManager

ComponentManager componentManager = ComponentManager.getInstance()
def watcherManager = componentManager.getWatcherManager()
def userManager = componentManager.getUserUtil()

def watchUsers = {usernames ->
usernames.each { def user=userManager.getUser(it) watcherManager.startWatching(user,issue.getGenericValue()) }
}

def users = ["X"]
watchUsers(users)

However, I find the below errors in my log file

at java.lang.Thread.run(Thread.java:662)
Caused by: javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: watcherManager for class: com.atlassian.crowd.embedded.ofbiz.OfBizUser
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:318)
	at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:111)
	... 185 more

3 answers

1 accepted

0 votes
Answer accepted
Pushparaj Bhaskaran July 11, 2013

Anyone can help ?

Pushparaj Bhaskaran July 14, 2013

ANother clue is that this script works on the Script Console , but in the post script function it fails

Pushparaj Bhaskaran July 16, 2013

Looks like this thread is thread. This is urgent and needs some help

2 votes
ctbto April 18, 2016

Updated version for JIRA 7.1.4:

 

 

import com.atlassian.jira.component.ComponentAccessor

def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()

 def watchUsers = {usernames ->
   usernames.each {
         def user = userManager.getUserByKey(it.toString())
         watcherManager.startWatching(user, issue)
      }
}

def users = ["user1", "user2"]
watchUsers(users)
Jordi Federico February 28, 2017

tested on 7.2.0 . It works as expected! Thank you

Stefani Kaimakliotou October 24, 2017
->

 In Jira Server 7.3.0 shows a problem with that symbol '-' 

Can you tell me what changed? I want the same code to work for the new version of jira SD.

Hoang Tran December 7, 2017

@Stefani Kaimakliotou were you able to solve that issue?  Thanks!

Stefani Kaimakliotou December 7, 2017

We upgraded to server 7.5 and chose not to use the addition of the user to the watchers list. I found another way solving my case. Thanks a lot. 

Like Alibek Malikov likes this
Vitaly Alimirzoev August 10, 2018

@Stefani Kaimakliotou
-> - it is just a "->"

Like mani@123 likes this
0 votes
Pushparaj Bhaskaran July 16, 2013

Had to add this to make it work, but atlast it is working as expected

package com.onresolve.jira.groovy.canned.workflow.postfunctions

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events