Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automatic Watchers

Deleted user May 29, 2018

i use the following script to add myself and another team member to be watchers of ALL tickets.... as you can imagine it gets a little daunting.

 

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 = ["slopez", "llucania"] watchUsers(users)

 

Our helpdesk is broken into two request types -  "Response Support" and "Helpdesk Support"

What would I modify in the script above to set myself to be added to all "Helpdesk Support" tickets only, and to have my other Colleague added to "Response Support" only.

 

1 answer

0 votes
Eric Lemay
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.
May 29, 2018

Hi Steven, 

 

You can probably use something like this, assuming that you have no other request types with the words 'response' or 'helpdesk' in your project.  You can change the lists of usernames to add different people to the different request types.

import com.atlassian.jira.component.ComponentAccessor

def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def reqtype = issue.getCustomFieldValue(customField)

def helpdeskusers = ["slopez"]
def responseusers = ["llucania"]

if (reqtype.toLowerCase().contains('response')){
watchUsers(responseusers)
}
else if (reqtype.toLowerCase().contains('helpdesk')){
watchUsers(helpdeskusers)
}

def watchUsers = { usernames ->
usernames.each {
def user = userManager.getUserByKey(it.toString())
watcherManager.startWatching(user, issue)
}
}

Let me know if that works?

Deleted user May 29, 2018

Thank you for the super quick reply. I am getting a few error messages when inputting the script into the workflow.

 

Attaching which lines are bad and a snip of where my request types lay (sorry not too familiar with JIRA yet)

 

jirasuport.PNG

Eric Lemay
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.
May 29, 2018

Generally speaking you should be able to simply ignore some of those errors.  It can help to diagnose issues with it fails, but it tends to flag things that won't necessarily be a problem.  That being said, I did a small update to the watchUsers section that might help.

This might still produce some warnings, but these are really just that: warnings.  Make sure you try it first and see what happens.  more on that here

def watchUsers(usernames) {
usernames.each {
def user = userManager.getUserByKey(it.toString())
watcherManager.startWatching(user, issue)
}
}
Deleted user May 29, 2018

No dice unfortunately. created tickets with both changes. 

 

errors are on line 21/22 saying usermanager/watchermanager is undeclared 

Eric Lemay
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.
May 29, 2018

I've done an edit to it, moving the variable declarations:

 

import com.atlassian.jira.component.ComponentAccessor


def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def reqtype = issue.getCustomFieldValue(customField)

def helpdeskusers = ["slopez"]
def responseusers = ["llucania"]

if (reqtype.toLowerCase().contains('response')){
watchUsers(responseusers)
}
else if (reqtype.toLowerCase().contains('helpdesk')){
watchUsers(helpdeskusers)
}

def watchUsers(usernames) {
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
usernames.each {
def user = userManager.getUserByKey(it.toString())
watcherManager.startWatching(user, issue)
}
}
Deleted user May 30, 2018

still didnt work unfortunately.

Thank you for all your help but i'll just leave be as now, or just do it based off SLA's, would still go to both of us but would drastically cut down on the emails we both receive.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events