Here the sample code to add a fixed watcher on the create issue transition of a Workflow. Very easy and useful script! This is a script PostFunction of the Adaptavist Groovy ScriptRunner Atlassian JIRA Plugin.

You can add, for example, a user linked to an email of a distribution list.

import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField cf_type= customFieldManager.getCustomFieldObject("customfield_XXXX") //Typical select combo field
def type= issue.getCustomFieldValue(cf_type)

if ( "${type}"== 'SOME VALUE OF THE SELECT COMBO FIELD') {
def userManager = ComponentAccessor.getUserManager()
WatcherManager watcherManager = ComponentAccessor.getWatcherManager()
watcherManager.startWatching(userManager.getUserByName("user_linked_to_a_distribution_email_list_for_example"), issue)
}
Posted by:.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s