Need to add specific watcher only when a specific person is assigned a JIRA ticket

A Project manager in our company wants to be automatically added as a watcher on tickets of another project only if it is assigned to a specific developer.

I think the parts that has me stumped is first, the "ticket of another project" part,

then second, how do I automatically trigger the "add watcher" only if the ticket is assigned to a specific developer?

The project manager certainly doesn't want to be added as a watcher to all the "other project" tickets, which is understandable since it's not their project, but does want to know when their developer is working on other projects managed by other project managers".

I'm guessing at least on part of the setup would involve adding the project manager to a role in the "other project"?

I'd really appreciated any thoughts and suggestions!

 

 

 

1 answer

0 vote
Mahesh S Community Champion Jun 10, 2016

As a first step, Please add your Project Manager into required role and provide sufficient permissions in the other Project. Use the below script  to check the assignee, whether he is your developer or not. If yes, assign it to your project manager. Sorry, that I couldn't test and provide you the verified script here, since I am away from my work station.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
  
IssueManager issueManager = ComponentAccessor.getIssueManager();
String assignee = (String) issue.getAssignee()
if((assignee == 'developer1') || (assignee == 'developer2') || (assignee == 'developer3'))
{
def userManager = ComponentAccessor.getUserManager()
def user = userManager.getUserByName("MyProjectManager")
def id=issue.getId()
watcherManager.startWatching(user, issue.getIssueObject(id))
}

Note: Kindly modify the developer and MyProjectManager usernames.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

458 views 7 8
Read article

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