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.
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?
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No dice unfortunately. created tickets with both changes.
errors are on line 21/22 saying usermanager/watchermanager is undeclared
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.