Add Watcher's based on custom field options

Hi There,

We have a Select list custom field named "Platform". We want to add only specific users to watchers field based on the options selected with help of groovy script in post function. The script composed below adds all the users (user1 to user6) and does not check for the values selected. Kindly help me in modifying the script.


import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor

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

def cf = customFieldManager.getCustomFieldObjects()?.find{it.untranslatedName == 'Platform'}

def watchUsers = {usernames ->
usernames.each {
def user = userManager.getUser(it)
watcherManager.startWatching(user, issue.getGenericValue())
if (cf) {

def cfValue = 'option1'
cfValue = issue?.getCustomFieldValue(cf)?.value
def users = ["user1", "user2"]

def cfValue2 = 'option2'
cfValue2 = issue?.getCustomFieldValue(cf)?.value
def usersA = ["user3", "user4"]

def cfValue3 = 'option3'
cfValue3 = issue?.getCustomFieldValue(cf)?.value
def usersB = ["user5", "user6"]

else {
log.error "Customfield 'My Custom Field' not found."


1 answer

0 vote

You want:

if (issue?.getCustomFieldValue(cf)?.value == "option2) {
else if (...)

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Service Desk

Wy are we still using email for Service Desk workflows?

...attest to the experience of an urgent approval that gets lost in the boss’s inbox and requires that special “Please Approve” email or text message. In an age where we have distributed teams...

111 views 0 2
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