Add Watcher's based on custom field options

CCP TechOps October 24, 2014

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"]
watchUsers(users)

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

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

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

 

1 answer

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 30, 2014

You want:

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

Suggest an answer

Log in or Sign up to answer