Post function Script to add a watcher for specific issue

Pritesh Jagani October 17, 2017

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

0 votes
Pritesh Jagani October 18, 2017

Here's the solution

GroovyRE.JPG

0 votes
MoroSystems Support
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.
October 17, 2017

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

Pritesh Jagani October 18, 2017

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


Pritesh Jagani October 18, 2017

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?

MoroSystems Support
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.
October 19, 2017

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!

Suggest an answer

Log in or Sign up to answer