Post function Script to add a watcher for specific issue

Hi ,

 

I am getting following error

Time (on server): Mon Oct 16 2017 17:37:53 GMT-0700 (Pacific Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-10-16 17:37:53,779 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-10-16 17:37:53,779 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CR-2024, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: event for class: Script54
 at Script54.run(Script54.groovy:8)


Here's my script

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.watchers.WatcherManager

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

def issue = event.getIssue()

def user = userManager.getUserByName("Brian66481")

if (issue.getIssueType().getName() == "RE Task") watcherManager.startWatching(user, issue)


Please help

2 answers

Hello Pritesh,

the problem seems to be at the line "def issue = event.getIssue()". The event variable is not available for your script. 

I think if you will delete the whole line, the issue will disappear (as the issue variable is automatically available in post function scripts).

Please let me now if it helped.
Regards,
Martin

Hi Martin,

 

Unfortunately it still doesn't work.

Following is the error-

Time (on server): Wed Oct 18 2017 10:06:10 GMT-0700 (Pacific Daylight Time)

The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.

2017-10-18 10:06:10,286 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-10-18 10:06:10,302 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: DBCR-443, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: event for class: Script210
 at Script210.run(Script210.groovy:17)


GroovyRE.JPG


Hey Martin!!!!!!!!
Thanks soooooo much!!!!!!! Been struggling from past 2 days!


It worked! 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.watchers.WatcherManager

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


def user = userManager.getUserByName("Brian66481")

if (issue.getIssueType().name == "RE Task")
watcherManager.startWatching(user, issue)

 

 

One more help  - I want to add user as a watcher based on task type and specific components.

Could you help me with that please?

Hello Pritesh,

sorry I couldn't answer you sooner but I see by your posted answer that you made it past your problem. Great to hear that!

Here's the solution

GroovyRE.JPG

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 7 hours ago in Confluence

Three common content challenges + how to manage them

An efficient enterprise content management system, or ECM, is a must-have for companies that create work online (cough   cough, all companies). If content calendars, marketing plans, and bu...

21 views 0 3
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