how to set watcher based on custom field

i want to set watchers based on custopm field i'm trying this code but he don't work using script running

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.watchers.WatcherManager
String userName;
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("supp")
def someUser = issue.getCustomFieldValue(cf)
def WatcherUser =ComponentAccessor.getUserManager().getUserByName(userName)
def watcherManager = ComponentAccessor.getWatcherManager()

2 answers


it depends on the type of your "supp" custom field. You need to convert the result of getCustomFieldValue into a username first.

Or you can use JIRA Misc Workflow Extensions instead ;)


haw to do it ?
can you send me the code ?

As I said, it depends on the type of your custom field. Is it a user picker? A Single-select type field? Text field? Something else?



That's because ScriptRunner doesn't know the type of the someUser variable. Write everything on one line instead.

the problem that when i show the result of watchermanager = user(user) 

that's why she don't work because my user is :


and the result of watcherUser  is 

user (user)

Time (on server): Mon May 22 2017 17:37:55 GMT+0100 (Afr. centrale Ouest)

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

2017-05-22 18:37:55,557 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-05-22 18:37:55,557 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script>
at com.atlassian.jira.issue.watchers.DefaultWatcherManager.updateWatch(
at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(
at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(
at com.atlassian.jira.issue.watchers.WatcherManager$ Source)

1 vote
Andreas Knecht Community Champion May 22, 2017

Hi Taher,

You could also do this with a simple automation rule with Automation for JIRA (full disclosure: I'm one of the authors).


So whenever the 'My User Picker' field's value changes, this rule will add the new value to the list of watchers on the issue.

You could also change the trigger to be something like 'Issue updated' and add various conditions to the rule, to only add the watcher if say the issue matched a given workflow status.


i'm using ScriptRunner for JIRA 

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 13, 2019 in Marketplace Apps

Marketplace Spotlight: Marketing apps for Confluence to keep your teams working on the same page


251 views 0 6
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