Hello,
I'm trying to remove a watcher from an issue when it's created. I use a custom listener with the 'Script Runner' plugin (I'm using JIRA v5.2.9 and Scipt Runner v2.1.15).
Here is my script listener :
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.issue.IssueEvent class AutoRemoveWatcherListener { void workflowEvent(IssueEvent event) { def watcherManager = ComponentAccessor.getWatcherManager() def userManager = ComponentAccessor.getUserManager() def user = userManager.getUser('myUser') watcherManager.stopWatching(user, issue) } }
Problem : it doesn't work !
Community moderators have prevented the ability to post new answers.
You haven't defined "issue", you want somewhere:
def issue = event.issue
It still doesn't work. I tried to use that script as a postfunction and as a custom listener. I even tried to extend the class AbstractIssueEventListener but no results.
My script is directly placed at the atlassian-jira/WEB-INF/classes/ folder.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Decide on whether you want a postfunction or a listener, the scripts will be different.
Start with a postfunction because it's easiest.
If that doesn't work post your code and the errors from the log.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes the code in the postfunction is different from the listener, here it is :
import com.atlassian.jira.component.ComponentAccessor def watcherManager = ComponentAccessor.getWatcherManager() def userManager = ComponentAccessor.getUserManager() def user = userManager.getUser('myUser') watcherManager.stopWatching(user, issue)
Here is the code with the log, but it appears that I have nothing in the logs file (catalina.out and atlassian-jira.log)
import com.atlassian.jira.component.ComponentAccessor import org.apache.log4j.Category def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction") log.setLevel(org.apache.log4j.Level.DEBUG) log.debug "--------------- REMOVE_WATCHER_SCRIPT --------------" def watcherManager = ComponentAccessor.getWatcherManager() def userManager = ComponentAccessor.getUserManager() def user = userManager.getUser('myUser') watcherManager.stopWatching(user, issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. You've choosen the wrong place to store listeners: please try to store under scripts folder under jira data folder g:\jiradata\6.3\scripts\com\polontech\listener\ExampleListener.groovy - see example
2. You should define the issue like
def issue = issueEvent.getIssue();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
do you see script listeners under script runner menu?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes I see it, then I choose 'Custom Listener' and when I provide the name of my script class, there are no errors so I suppose this is not a folder problem.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok then, but you still need to get issue from the issue event to make this script workable
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What's in the log? Maybe a class-cast problem, with ApplicationUser and User.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.