I have this script I'm using as a post function for adding a watcher during a workflow transition. I don't know how to write script, I found it, lol. How could I narrow it down to only run when a specific project is using the workflow?
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue
def userName = "BM0987" // name of the user
def userManager = ComponentAccessor.getUserManager()
MutableIssue issues = issue as MutableIssue
def user = userManager.getUserByName(userName)
def watcherManager = ComponentAccessor.getWatcherManager()
watcherManager.startWatching(user, issue)
Hi @Ashley
For your requirement, you can try something like this:-
import com.atlassian.jira.component.ComponentAccessor
def userManager = ComponentAccessor.userManager
def watcherManager = ComponentAccessor.watcherManager
def project = issue.projectObject
def username = 'BM0987'
if (project.key == 'MOCK') {
def user = userManager.getUserByName(username)
watcherManager.startWatching(user, issue)
}
Please note that the sample code above is not 100% exact to your environment. Hence, you will need to modify it accordingly.
I have added a filter for the project key in the code above. Hence, the watch manager will update the watcher only if an issue belongs to that particular project.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
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.