Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

On the create transition, I'd like to add watchers based on checkbox custom field selection

David Mason
Contributor
June 27, 2018

We're using scriptrunner, and I'd like to custom script a post function to do this.  I've given it a shot, and I'm not getting the watchers, but there are no errors. 

 

Here's the most recent version of the script...

 

import com.atlassian.jira.component.ComponentAccessor

log.debug "In WATCHER Script"

def CustomFieldManager = ComponentAccessor.getCustomFieldManager()
def websiteCustomField = CustomFieldManager.getCustomFieldObjectByName('Website')
def websiteValue = issue.getCustomFieldValue(websiteCustomField)

log.debug 'websiteCustomField is' + websiteCustomField
log.debug 'websiteValue is ' + websiteValue

if(websiteValue == '[Oracle Commerce Backend]') {
def watcherManager = ComponentAccessor.getWatcherManager()
def userManager = ComponentAccessor.getUserManager()
watcherManager.startWatching(userManager.getUserByKey('user1'), issue)
watcherManager.startWatching(userManager.getUserByKey('user2'), issue)
log.debug('user1 and user2 should be watchers')
}

 

 

2 answers

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2018

Hello,

I guess you are not entering the if condition. Are you sure that you enter the if condition? Specifically [Oracle Commerce Backend] does  not look right for comparison. Does it mean that the websiteValue is a List? what is the type fo the Website custom field?

If websiteValue is a list, your comparison should look like this:

websiteValue.first() = 'Oracle Commerce Backend'

or you can try

'Oracle Commerce Backend' in websiteValue
0 votes
Tushar
Contributor
June 27, 2018

Hi,

 

You can try below free add on which help you to add watchers at the creation of the request.

https://marketplace.atlassian.com/apps/6306/watcher-custom-field-for-jira?hosting=server&tab=overview

Suggest an answer

Log in or Sign up to answer