i want to add a new post-function on workflow to achieve auto adding watchers function for service desk project.
like: when email subject contain "Job-Failed", then ticket auto add a few watchers
when email subject does not contain" Job-Failed", then create ticket as normal
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
def cfManager = ComponentAccessor.getCustomFieldManager()
// i think "Summary" is the subject field of email
def cf = cfManager.getCustomFieldObjectByName("Summary")
if (issue.getCustomFieldValue(cf).toString().equals("Job-Failed")) {
def watchUsers = { usernames ->
usernames.each {
def users = userManager.getUserByKey(it.toString())
watcherManager.startWatching(users, issue)
}
}
def users = ["seed", "ops", "ewss", "wwd", "ssee"]
watchUsers(users)
}
This is my code, some errors came out from:
if (issue.getCustomFieldValue(cf).toString().equals("Job-Failed")) Can anyone give me some suggestions? i am not good at groovy.