Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to add watchers to a jira ticket starting from the email in a cascading cf

DOMENICO TROISI
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 19, 2018

Hi to all,

in a cascading custom field (opening mask) is contained one or more email of jira user. Is it possible, to add all the users contained in the second field of cascading as whatchers of a ticket via script post function?
I believe that from the email it is necessary to extract the user code before adding it as a watcher.

Many thanks! Regards,

Domenico

 

1 answer

1 accepted

1 vote
Answer accepted
Carmen Creswell [Adaptavist]
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.
December 19, 2018

Hi Domenico! 

Here is a way that worked in my instance: 

import com.atlassian.jira.bc.user.search.UserSearchService
import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfValue = customFieldManager.getCustomFieldObjectsByName("CascadingSelect")[0].getValue(issue)

def addresses = cfValue.get(null)?.childOptions*.value

def watcherManager = ComponentAccessor.getWatcherManager()
def userSearcherService = ComponentAccessor.getComponent(UserSearchService)

def theUser

for (def i = 0; i < addresses.size(); i++) {
theUser = userSearcherService.findUsersByEmail(addresses[i])
// Using theUser[0] because the User is an ArrayList of a single ApplicationUser
watcherManager.startWatching(theUser[0], issue)
}

You'll just need to change the name of the Cascading Select field to the name that matches the one in your instance. 

Suggest an answer

Log in or Sign up to answer