Script runner clone issue function - add watcher in target issue

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 30, 2014

Hi All,

I am struggling to add watcher to an issue, the problem here is that

def user = userManager.getUserObject("userid") 
if (user) watcherManager.startWatching(user, issue)

the above snippet works fine if it's placed in the post-function of the "issue", but what i am trying to achieve is that I am trying to clone an issue using script runner and during that process I am trying to add the assignee of the original issue as a watcher in the issue to be cloned and all this is in the post-function of the original issue thus while logging i get the error

[jira.issue.watchers.DefaultWatcherManager] You must specify an issue.

As I understand the above error is because the issue to be cloned as not yet been created and I am trying to add a watcher to it but is there another way to fix this problem apart from wirting a post-funciton in the cloned issue
Thanks!

1 answer

1 accepted

0 votes
Answer accepted
Tanner Wortham
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.
July 31, 2014

I feel like I may be overlooking something obvious with my answer, but I'm not sure what it is. At some point in your post-function, the issue is, in fact, created, right? So why not add the previous assignee as a watcher with code similar to the above after the clone is alive and well and before the post-function completes?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 31, 2014

Hi Tanner,

I don't think the target issue(issue to be cloned) is created in the post-function as the whole point of using the post function is to create the issue itself, and once the post-fcuntion executes only then the target issue is created.

Tanner Wortham
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.
July 31, 2014

I think I know what I missed now. You're using a pre-existing script to clone. I was under the impression that you had already authored your own code to do the cloning. Why not take that pre-existing code, modifying it a bit to fit your needs, and then using as your own custom post-function?

Tarun Sapra
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 3, 2014

Actually I was looking for a way to avoid custom code, as in a Large and complex jira instance, custom code sometimes add to maintenance woes of admins/developers

Tanner Wortham
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.
August 3, 2014

yep. it can be a headache sometimes.

Suggest an answer

Log in or Sign up to answer