Groovy Scripts for adding watcher based on Priority

Hello,

I am looking for a way to use a groovy script to assign watchers of a ticket on creation based on the priority assigned.

Does anyone know if this is possible or has anyone successfully done this before?

Thanks!!

3 answers

1 accepted

This widget could not be displayed.

Made that change which resulted in another error... thanks for your help, maybe we can get this working with a little more tweaking...

current error:

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script3.groovy: 36: unable to resolve class MutableIssue
@ line 36, column 14.
MutableIssue mutableIssue = (MutableIssue) issue;
^

Script3.groovy: 36: unable to resolve class MutableIssue
@ line 36, column 29.
MutableIssue mutableIssue = (MutableIssue) issue;
^

2 errors

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:858)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:548)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:497)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getScriptClass(GroovyScriptEngineImpl.java:337)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:109)
... 147 more

Where are you copying/adapting this from? You are missing the imports.

This widget could not be displayed.

Script I tried below:

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

import com.atlassian.jira.ComponentManager

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

//******************Declaring watchUsers function**********************************
def watchUsers = {usernames ->
usernames.each {
def user = userManager.getUser(it)
watcherManager.startWatching(user, issue.getGenericValue())
}
}
//******************End Declaration of watchUsers function*************************

////******************Defining user groups*******************************
def SHOWSTOPPER_users = ["testuser1"];
def HIGH_users = ["testuser2"];
def MEDIUM_users = ["testuser3"];
def LOW_users = ["testuser4"];
def VERYLOW_users = ["testuser5"];
////******************End user group definitions*************************

////******************Defining user test groups*******************************
def SHOWSTOPPER_test = ["testuser1"];
def HIGH_test = ["testuser2"];
def MEDIUM_test = ["testuser3"];
def LOW_test = ["testuser4"];
def VERYLOW_test = ["testuser4"];
////******************End user test group definitions*************************



MutableIssue mutableIssue = (MutableIssue) issue;
def priority = mutableIssue.getPriority().getString("name");

if(priority.equals("5-Showstopper")){
//Assign to watchers who need for showstopper
//watchUsers(SHOWSTOPPER_users);
watchUsers(SHOWSTOPPER_test);
}
else if(priority.equals("4-High")){
//Assign to watchers who need for high
//watchUsers(HIGH_users);
watchUsers(HIGH_test);
}
else if(priority.equals("3-Medium")){
//Assign to watchers who need for medium
//watchUsers(MEDIUM_users);
watchUsers(MEDIUM_test);
}
else if(priority.equals("2-Low")) {
//Assign to watchers who need for low
//watchUsers(LOW_users);
watchUsers(LOW_test);
}
else if(priority.equals("1-Very Low") ) {
//Assign to watchers who need for very low
//watchUsers(VERYLOW_users);
watchUsers(VERYLOW_test);
}
else //No priority is assigned.
//Assign no watchers one.

Error I found in the JIRA log after running:

Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 65: unexpected token: @ line 65, column 28.
//Assign no watchers one.
^

1 error

at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:141)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:107)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:160)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:843)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:548)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:524)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:501)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getScriptClass(GroovyScriptEngineImpl.java:337)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:109)
... 147 more

Looks like your script ends with the keyword "else" ?

That's not valid.

Just remove the final "else"... then it should be ok.

This widget could not be displayed.

That did it! Thank you!

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Published yesterday in Marketplace Apps

The 7 hacks of highly successful automation

...there's anything I've learnt from working, it's that people are lazy! No offense to anyone reading this, but it's true and we can all admit it. The easier you make something for someone, the more...

166 views 0 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you