Hello All,
I have added below script in script runner postfunction on create transition to automatically add user to the Watcher field on create transition. But below script is adding only single user to the watcher field, How do i add multiple users to watchers field?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
def userName = "Atanu_Mandal" // name of the user
def userManager = ComponentAccessor.getUserManager()
MutableIssue issues = issue as MutableIssue
def user = userManager.getUserByName(userName)
def watcherManager = ComponentAccessor.getWatcherManager()
watcherManager.startWatching(user, issue)
Thanks in advance,
CH
If you have a collection of usernames, you can use for loop to add those users to the watchers. This code is untested but should give you a rough idea.
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
List userNameList = ["Atanu_Mandal", "user1", "user2"]
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
MutableIssue issues = issue as MutableIssue
for (def userName: userNameList) {
def user = userManager.getUserByName(userName)
watcherManager.startWatching(user, issue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your script is only getting one user, what other users do you want to add as a watcher and how are you fetching them? are they going to be hardcoded 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.