Add watchers at issue creation

Alex
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 10, 2022

Hello, i get an error in logs my post-function (in Workflow)

my code :

import com.atlassian.jira.component.ComponentAccessor

def watcherManager = ComponentAccessor.getWatcherManager()

def userManager = ComponentAccessor.getUserManager()

def watchUsers = {usernames ->

    usernames.each {

        def user = userManager.getUserByKey(it.toString())

        watcherManager.startWatching(user, issue)

    }

}

def users = ["n.lubyanskaya", "a.belyaeva","e.fedoseeva", "e.dushnova", "l.golovanova", "a.zaretskaya","v.moshkarova","a.zamekhovskaya","e.kozhukhova"]

watchUsers(users)

What could be the problem ?


logs:
 

2022-06-10 11:18:51,737 ERROR [watchers.DefaultWatcherManager]: You must specify a user.
2022-06-10 11:18:51,817 ERROR [watchers.DefaultWatcherManager]: You must specify a user.
2022-06-10 11:18:51,888 ERROR [watchers.DefaultWatcherManager]: You must specify a user.
2022-06-10 11:18:51,928 ERROR [watchers.DefaultWatcherManager]: You must specify a user.
2022-06-10 11:18:51,962 ERROR [watchers.DefaultWatcherManager]: You must specify a user.

 

1 answer

1 accepted

1 vote
Answer accepted
Vikrant Yadav
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 10, 2022

Hi @Alex  Kindly use following script for adding multiple users as watcher, update usernames as per your requirement :- 

Kindly move scripted post function after "Creates the issue originally." post function, if you are applying script on create issue transition.  

import com.atlassian.jira.component.ComponentAccessor

def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()

def watcher = ["username1","username2"]

watcher.each{userName->
def user=ComponentAccessor.userManager.getUserByName(userName)
watcherManager.startWatching(user, issue)
}

 Thanks

V.Y

Alex
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 10, 2022

@Vikrant Yadav  , thank you very much, everything works! Have a nice day! :)

Like Vikrant Yadav likes this
Vikrant Yadav
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 10, 2022

You’re Welcome 😇 Have a great weekend 

Like Alex likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events