Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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)
}

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! :smile::smile::smile:

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?

Hi,

I'm a beginner with Script Runner and your scripts are exctly what I need, but they don't work for me.

I've tried all 3 suggested scripts and got the same error: "The variable [event] is undeclared".

I'm using Jira server 7.5.3 and wish to add a watcher as a post function to a transition.

Please advise.

0 votes
Steven Behnke Community Leader May 06, 2016

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

Steven, 

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

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

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
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,881 views 11 5
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you