Scriptrunner

Stanislav
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 2, 2021

Im new to scriptrunner
Add user (Tom Thomas) as a watcher on an issue if assignee is (John Johnson) in a certain project, for example project ABC. Where i should write script ? Behaviour, post function, listeners ?
If you can provide me with a script it would be perfect 

2 answers

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 2, 2021

Listener would be best, because it can update the watchers on edit as well as transition.

https://library.adaptavist.com/entity/automatically-add-watchers-to-newly-created-issues

should get you started.  You'll want to change the events it's looking at (create, update, assign and possibly transition if you change assignees during transitions), and add a bit of logic for "if user X then add watcher Y", but most of what you need is there.

Stanislav
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 3, 2021

if assignee was added not at the creation of issue but later in the workflow or have been changed will it work?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 3, 2021

That's what the listener is for - it can catch "edit" and "assign" events where the assignee may be changed.

So yes, it can pick up the current assignee whenever it changes.

Like Stanislav likes this
Stanislav
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2021

@Nic Brough -Adaptavist-  What do you think about this code will it work

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)
}
0 votes
Daniel Ebers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 6, 2021

Suggest an answer

Log in or Sign up to answer