Automatically adding watchers every time a specific issue type created

Hello, 

How can I add specific users as watchers every time an " error " issue type created? I have checked the link below and provided scripts below does not work for me.- We use JIRA 7.1.

Thank you.

https://answers.atlassian.com/questions/95087

7 answers

This widget could not be displayed.

Oh man, you should do some Java tutorials to learn a bit programming.

 

import com.atlassian.jira.component.ComponentAccessor
 
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
 
def issue = event.getIssue()

def user1 = userManager.getUserByName("dustan")
def user2 = userManager.getUserByName("gabby")
def user3 = userManager.getUserByName("Phillip")
def user4 = userManager.getUserByName("Gerald")
def user5 = userManager.getUserByName("elif")
def user6 = userManager.getUserByName("jon")
if (issue.getIssueType().getName() == "New Contractor")
{
  watcherManager.startWatching(user1, issue)
  watcherManager.startWatching(user2, issue)
  watcherManager.startWatching(user3, issue)
  watcherManager.startWatching(user4, issue)
  watcherManager.startWatching(user5, issue)
  watcherManager.startWatching(user6, issue)
}
This widget could not be displayed.

Just replace "Bug" with your issuetype and "robin" with your username.

import com.atlassian.jira.component.ComponentAccessor

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

def issue = event.getIssue()
def user = userManager.getUserByName("robin")

if (issue.getIssueType().getName() == "Bug") watcherManager.startWatching(user, issue)

Regards,

Robin

Robin, 

I am using script Listener to add the watchers and here is what I am getting. I am not familiar with wring scripts, so please be patient with me smile

Thank you for your understanding,

 

I would insert the script to workflow.

Navigate Administration/Issues/Workflows

Edit the workflow you want to change.

Go to the "Create" transition, add a post function, chose "Script Post-Function" and there "Custom script post-function". Paste the code and publish workflow.

As a listener, you have to add:

def issue = event.getIssue()

to line 5.

If the project is using the default JIRA workflow - not a custom one- , will the other projects using the default Jira workflow will be impacted? Or not?

If you want to use script listener, i updated my first post with the declaration of "issue".

Best,

Robin

Script Listener works!!!!! Thank you so much, you made my day! smilesmilesmile

I am curious though.If I have added the transition you have mentioned above the default workflow that my project associates with  , would it impact all the other projects which have been using the default JIRA Workflow?

If you edit the standard workflow, all projects using this workflow will be impacted.

So, use the Script Listener with the extended code from above. smile

THANK YOU SO VERY MUCH!

Robin, 

When I added multiple people on the script I am getting this message, any ideas?

image2016-5-6 12:51:5.png

Robin, can you please send me the command line for adding multiple users. This is what I used , but I am getting the error message I posted above. 

 

def user = userManager.getUserByName("Amy", "Sally", "Phillip", "Jack", "elif", "john”)

Thankyou @Robin Peters the script runner works excellent on JIRA 7.2.3. But, the script failed on workflow post function (custom script).Thank you so much you made my day. 

Hi Robin,

 

I am getting following error

Time (on server): Mon Oct 16 2017 17:37:53 GMT-0700 (Pacific Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-10-16 17:37:53,779 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-10-16 17:37:53,779 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CR-2024, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: event for class: Script54
 at Script54.run(Script54.groovy:8)


Here's my script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.watchers.WatcherManager

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

def issue = event.getIssue()

def user = userManager.getUserByName("Brian66481")

if (issue.getIssueType().getName() == "RE Task") watcherManager.startWatching(user, issue)


Please help

Where you want to run that script? Inside of a transition?

This widget could not be displayed.
Steven Behnke Community Champion May 06, 2016

Why don't the scripts in that link work for you?

This widget could not be displayed.

Steven, 

I have posted the error messages I am getting below. Any idea?

This widget could not be displayed.
This widget could not be displayed.

Hello, 

Can anyone please help me to fix the line below for the script runner? 

def user = userManager.getUserByName("dustan", "gabby", "Phillip", "Gerald", "elif", "jon”) 

here is the error message I am getting:

image2016-5-6 13:1:32.png

This widget could not be displayed.

1.png2.png

Here is the script I am using. Ofcourse, I am using logon name where it says firstname.lastname but it isnt working for me. 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

217 views 1 3
Join discussion

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