Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,644
Community Members
 
Community Events
165
Community Groups

Add watchers at issue creation

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

Hi @Oliver Smith  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

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

Like Vikrant Yadav likes this

You’re Welcome 😇 Have a great weekend 

Like Oliver Smith likes this

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

312 views 2 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you