Hello team i would like to add watchers from 2 custom fields (user picker) .
I need your help please .
I use this code but it doesn't work.
import com.atlassian.jira.component.ComponentAccessor def watcherManager = ComponentAccessor.getWatcherManager() def userManager = ComponentAccessor.getUserManager() def user = userManager.getUserObject("Michellee") if (user) watcherManager.startWatching(user, issue.genericValue)
Regards
Hello Karim,
Thank you for reaching out.
Using a Scriptrunner post function, I believe the Groovy Script below should work for you. P.S: Assuming your custom field ID is "12345" and its type is a text (single line):
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def cf = cfManager.getCustomFieldObject((Long) 12345)
def user = userManager.getUserByName("username")
if (issue.getCustomFiledValue(cf).equals("value")){
watcherManager.startWatching(user, issue)
}
Also, you can check the three threads below for other solutions using Groovy Script:
- Adding a watcher through scriptrunner if a custom field is a certain value
- How to set watcher based on custom field with Scriptrunner
- I'd like to add watchers when a custom field value is true
Let me know if this information helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.