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 adds watchers based on a custom field Edited


How can i automatically adds watchers based on a custom field in JIRA when a issue is created?

I have the ScriptRunner plugin.

Does anyone know how I can do this using scriptrunner?

If anyone knows, could you provide me a script?

3 answers

1 accepted

0 votes
Answer accepted

@Fernanda de Souza Thaumaturgo 

I recommend to use Automation for Jira Lite by adding automation rule

- when issue is created

- if JQL result passed (custom field value = {Data})

- Add watcher

I already have ScriptRunner plugin, do you know if i can use this one to do this automation?

@Fernanda de Souza Thaumaturgo 

Try this code as post-function after issue created

import com.atlassian.jira.component.ComponentAccessor

//Get appropriate managers
def watcherManager = ComponentAccessor.getWatcherManager()
def cfManager = ComponentAccessor.getCustomFieldManager()

//Get your custom field object
def customField = cfManager.getCustomFieldObject().find{ == "Custom Field Name"}
//Get the custom field value
def userToWatch = issue.getCustomFieldValue(customField)

//Set the user to watch the provided issue
watcherManager.startWatching(userToWatch, issue)

Thanks @Muhammet_Adel !

Unfortunately this code only works for the server version.

But thank you so much for your help!

Like Muhammet_Adel likes this
0 votes
Joe_Pitt Community Leader Sep 19, 2019

You can't out of the box. You will need a plugin. I believe the Behaviors plugin will allow you to do it 

I already have ScriptRunner plugin, do you know if i can use this one to do this automation?

Hi Fernanda de Souza Thaumaturgo,

I can confirm that you will be unable to use Behaviours as responses have suggested within ScriptRunner for Jira Cloud as the cloud version of the plugin does not have the Behaviours feature like the server version does.

The reason we are unable to provide this functionality is due to the restricted functionality and API's which Atlassian provide inside JIRA Cloud, due to the fact that Atlassian only provides a Rest API in Jira Cloud and not the same Java API that the server version contains.

You can see more detailed information on the differences between ScriptRunner for JIRA Cloud and ScriptRunner for JIRA Server inside of the documentation page located here.

However, I can confirm that you can achieve this requirement inside of ScriptRunner for Jira Cloud by adding in a Run Script post function configured as the last post function, on the Create Transition of the workflow.

The script will need to get the custom field value off of the issue and if the custom field value matches the expected value then adds a user as a watcher on the issue.

I can confirm that we have lots of examples in the documentation page located here which show how to extract the values from different custom field types and that we have the example script located here which shows how you can add a user as a watcher. 

You will be able to take these scripts and will be able to use these as a reference guide to help create the script that you require.

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.



Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Keep your team in the loop with Team @mentions in Jira Software!

Hi everyone! My name is Jenny, a Product Manager at Atlassian. After launching Team @mentions in Confluence, we heard a lot of positive feedback from customers that they love how easy it is to @men...

555 views 6 18
Read article

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