Adding fixed watcher to a new issue using a post function

Hello,

we recently updated our JIRA to version 7.1.8.

Unfortunately one of our scripts doesn´t work any more.

The upcoming error is:

 /secure/CreateIssueDetails.jspa [c.a.j.issue.watchers.DefaultWatcherManager] You must specify a user.

This is the code:

import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
 
 
def customFieldManager = ComponentAccessor.getCustomFieldManager()
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 = ["<username>", "<username>", "<username>", "<username>"]
 
def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.setLevel(org.apache.log4j.Level.DEBUG)
log.debug "--------------- ADD WATCHER/S --------------"
 
watchUsers(users)

I tried some things but I unfortunately can´t find the error.

It seems like the users are defined wrong.

Can anyone see the error?

Best regards,

Michael

2 answers

hi Michael,

I think your script is right, so as you already noticed the problem should be with the user names, try to add a debug message for the user, and check the user for null before the watcherManager.startWatching(user, issue)

regards

Hi Thanos,

thanks for your answer.

I found the error. JIRA compares the lower case usernames.

So I just had to write the usernames in loser case and the csript worked fine.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

91 views 0 1
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you