Add watchers

arno
Contributor
October 26, 2023

Hi All

We have a custom field to store product information. Whenever a user creates an issue related to a bug, we hope to automatically add the corresponding leader as watchers according to the field value. I have looked at other documents in the community, but there seems to be no relevant solution

The jira we are using is the server version, and the corresponding Project automation does not have the option of managing watchers. I am trying to solve this problem using scriptrunner, but I am not sure how to get or assign the value to watchers

2 answers

1 accepted

0 votes
Answer accepted
Adrien Low _ServiceRocket_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 31, 2023

Hello @arno ,

If you could provide us with more information on your requirements, it would greatly help us to provide a better solution.

For example:-

  • Current Jira version
  • What has been implemented so far?

From what we can see, Jira Automation for Data Center does provide an action to manage Watchers:-

Screenshot 2023-10-31 170909.png

You should be able to manage your Watchers after configuring additional conditions.

If you would like to use ScriptRunner instead, you can configure a Custom script post-function [ScriptRunner] in your workflow with the below draft script:-

 

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserManager()
def watcherManager = ComponentAccessor.getWatcherManager()

def productInformationCF = customFieldManager.getCustomFieldObject('customfield_xxxxx') //ProductInformation

def productInformationValue = issue.getCustomFieldValue(productInformationCF)

def user

if(productInformationValue.equals("A")) {
user = userManager.getUserByName('charlie')
} else if(productInformationValue.equals("B")){
user = userManager.getUserByName('alpha')
} else {
user = userManager.getUserByName('beta')
}

watcherManager.startWatching(user, issue)

Hope this helps.

Regards.

0 votes
arno
Contributor
November 2, 2023

Hi @Adrien Low _ServiceRocket_ 

It works. Thank you for your help

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
AUG Leaders

Atlassian Community Events