You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi
Just wanted to share the code that @Benz Kek _Adaptavist_ helped me with for creating a listener that adds a user who is added to a jira issue in a user picker, as a watcher of the issue. As always the support from the Adaptavist team is fantastic - thanks again Benz.
We have a number of different people working on various Jira issues who are added under different userpicker custom fields by their managers, previously the manager would have to remember to manually add them as watchers.
Examples are 'photographer' or 'stylist'
The code below is the script inserted in a SR Listener, fired from (in my case) the' issue updated' event
It will only add the user as a watcher if have not already been added
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def watcherManager = ComponentAccessor.watcherManager
def userManager = ComponentAccessor.userManager
def issue = event.issue
def singleUserPickerFieldName = "User Picker Custom Field"
def singleUserPicker = ComponentAccessor.customFieldManager.getCustomFieldObjectsByName(singleUserPickerFieldName).first()
def user = (ApplicationUser) issue.getCustomFieldValue(singleUserPicker)
def currentWatcherUsernames = watcherManager.getCurrentWatcherUsernames(issue)
if (!(user.username in currentWatcherUsernames)) {
watcherManager.startWatching(user, issue)
}
This was exactly what I was looking for, thanks so much for sharing the code!