Hi Team,
We have a requirement to add watchers to the ticket based on a custom field value.
Add Watchers to the ticket automatically.
Add User1 and User2 if the CustomField is Value1
Add User3 and User4 if the CustomField is Value2
If both Values are selected add all 4 as watchers (User1, User2, User3, and User4)
Hi @Lakshmi S
For your requirement, it would be best to use ScriptRunner' Listener.
Below is a working sample code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
def issue = event.issue
def userPicker1 = issue.getCustomFieldValue('Multi User Picker 1') as List<ApplicationUser>
def userPicker2 = issue.getCustomFieldValue('Multi User Picker 2') as List<ApplicationUser>
def watcherManager = ComponentAccessor.watcherManager
def english = new Locale('en')
def currentwatchers = watcherManager.getWatchers(issue, english) as List<ApplicationUser>
if (userPicker1 || userPicker2) {
currentwatchers.each {
watcherManager.removeAllWatchesForUser(it)
}
currentwatchers = userPicker1 + userPicker2
currentwatchers.each {
watcherManager.startWatching(it, issue)
}
}
Please note that the working sample code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of the Listener configuration:-
If you observe the Listener configuration above, the Issue Created and Issue Updated events have been added.
Hence, when the issue is created, the Watcher list will be updated if any user is selected from either of the Multi-User pickers.
I hope this helps to answer your question. :-)
Thank you and Kind regards,
Ram
Hi @Lakshmi CH
You can use a Set Field Value post function, select the "Watchers" field, and use this script as the value:
def watchers = ( issue.get("Watchers") ?: [] )*.username
if ("Value1" in issue.get("Custom field")*.value)
watchers += ["user1","user2"]
if ("Value2" in issue.get("Custom field")*.value)
watchers += ["user3","user4"]
return watchers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.