Always add user (Tom Thomas) as a watcher on an issue if assignee is (John Johnson) in a certain project, for example project ABC.
Now i only have this code plz help
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
def cf = cfManager.getCustomFieldObject((Long) 11111)
def user = userManager.getUserByName("username")
if (issue.getCustomFiledValue(cf).equals("value")){
watcherManager.startWatching(user, issue)
}
Hi @Stanislav
It would be better to use the Post-Function and add a Custom Script to it.
You can try something like this:-
import com.atlassian.jira.component.ComponentAccessor
def watcherManager = ComponentAccessor.watcherManager
def userManager = ComponentAccessor.userManager
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
if(loggedInUser.name == "John Johnson") {
def watchUsers = { usernames ->
usernames.each {
def user = userManager.getUserByName(it)
watcherManager.startWatching(user, issue.genericValue)
}
}
def users = ["tthomas"] // use Tom Thomas' username not full name
watchUsers(users)
}
Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.
I hope this helps to answer your question. :)
Thank you and Kind regards,
Ram
@Ram Kumar Aravindakshan _Adaptavist_ But i don't see any assignee script in your code
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it is my biggest problem
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Stanislav,
If you want to set the watcher based on the assignee, you can modify the if condition to something like:-
if(assignee.name=="jjohnson") {
.
.
.
}
Below is the updated working sample code for your reference:-
import com.atlassian.jira.component.ComponentAccessor
def watcherManager = ComponentAccessor.watcherManager
def userManager = ComponentAccessor.userManager
def assignee = issue.assignee
def watcher = userManager.getUserByName("tthomas")
if(assignee.name=="jjohnson") {
watcherManager.startWatching(watcher, issue)
}
Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Or maybe this one that i find
import com.atlassian.jira.component.ComponentAccessor def watcherManager = ComponentAccessor.getWatcherManager() def userManager = ComponentAccessor.getUserManager() def user = userManager.getUserObject("userid") if (user) watcherManager.startWatching(user, issue.genericValue)
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.