Are you in the loop? Keep up with the latest by making sure you're subscribed to Community Announcements. Just click Watch and select Articles.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Copy value from user picker custom field to Watchers filed on custom field update

Edited

We have a request to copy values from two user picker fields to the Watcher filed whenever these fleds are updated. I have created a script listener which runs on issue update:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def sourceField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Technical Lead"}
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Watchers"}
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), issue.getCustomFieldValue(sourceField)),changeHolder)

 

But this does not update the watcher filed. We get the following error:

 

2017-12-13 10:21:39,209 ERROR [runner.AbstractScriptListener]: *************************************************************************************
2017-12-13 10:21:39,209 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
java.lang.NullPointerException
	at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896)
	at com.atlassian.jira.issue.Issue$getCustomFieldValue$9.call(Unknown Source)
	at Script48.run(Script48.groovy:11

I guess that the method for get and set Watchers filed is not correct. Can you please help us with that?

 

Regards,

Nadica

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Ivan Tovbin
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.
Dec 29, 2017 • edited

Hi Nadica,

Indeed, the way you are trying to set the value for 'Watchers' field seems to be the problem here.

Assuming 'issue.getCustomFieldValue(sourceField)' returns an 'Application User' object, try this:

def watcherManager = ComponentAccessor.getWatcherManager()

watcherManager.startWatching(issue.getCustomFieldValue(sourceField), issue)

 

TAGS
AUG Leaders

Atlassian Community Events