Forums

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

How to add watcher in a transition postfunction

Peter Kocher May 8, 2018

In a particular transition I change the assignee from developer to QA responsible, but would like to add the developer as watcher so he is still in the loop of his code.

I therefore would need a post function (script), that adds the previous assignee to the list of watchers.

 

Hoe can I do this?

4 answers

1 accepted

1 vote
Answer accepted
Marcos Sanchez
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.
May 8, 2018

Hi,

As I understand, you want to add to watchers list the last assignee before changing it on the post-function of a transition, right?

Adding this script just before the "change assignee" step of the post-function and it should work:

import com.atlassian.jira.component.ComponentAccessor

def watcherManager = ComponentAccessor.watcherManager
def userManager = ComponentAccessor.userUtil

def user = issue.getAssignee()

watcherManager.startWatching(user, issue)

 

Hope it helps.

Regards,
Marcos 

Peter Kocher May 8, 2018

Hi Marcos, I copy/pasted your suggested script, but it does not run. see attached JPG

Best - PeterJIRA script.JPG

0 votes
Roman Bliznak April 17, 2020

Hi @Marcos Sanchez ,

 

please can you help me how the script should look like if I need to add all users from a specified user role to Watchers?

Thanks!

Roman Bliznak

0 votes
Marcos Sanchez
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.
May 10, 2018

Hi,

Can you access to JIRA log? Maybe there will be more information about the transition execution and it could be something valuable.

Anyway, I've checked on my Jira and it works fine to me. I attach a screenshot of my configuration (same as yours).

2018-05-10_10h45_24.png

Sincerely, I don't know why it doesn't works to you, configuration is fine...

 

Regards,
Marcos

Peter Kocher May 10, 2018

Hi Marcos

I do not have access to the JIRA log, so I have to wait for out IT support, which I can contact personally early next week.

Please keep the ticket open until I come back

Thanks and best regards

Peter

Peter Kocher May 15, 2018

Hi Marcos

I found the error - I tested with a project, where the modified workflow was not assigned - too stupid !!

Your script works perfect.

Thanks again and please excuse the trouble you had with me :-(

Please close the ticket.

Best regards

Peter

Marcos Sanchez
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.
May 15, 2018

Hi!

 

Hahahaha don't worry!!

 

To close it, accept the first answer ;)

 

Regards!
Marcos

0 votes
Marcos Sanchez
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.
May 8, 2018

Hi,

It's not a script problem (as message says), so if you add it to the post-function and test it, it should work.

I recomment you to use a test environment or workflow to try it if you have one before implementing it to production.

Try it and tell me if it works.

 

Regards,

Marcos

Peter Kocher May 9, 2018

Hi MarcosJIRA script_1.JPG

I did what you told me and created a new (first) post function with the script. See attached screen shot. If not this way, how shall I add your script?

Thanks again and best regards

Peter

Marcos Sanchez
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.
May 9, 2018

Hi,

This configuration of the screenshot is fine.

I've just told you that the error that you get in the first screenshot is not a code error.

Did you tried to do the transtion and check if that all works?

 

Regards,
Marcos

Peter Kocher May 10, 2018

Good morning Marcos

Yes, I added the script to the JIRA test instance and processed through the workflow. As you can see in my last screen shot, the post function says: "Has not run yet", so it did not process and I do not know why not.

Best regards

Peter

Marcos Sanchez
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.
May 10, 2018

Hi,

Is the workflow correctly published?

I know that this question can be obvious but is just for checking.

 

Regards,
Marcos

Peter Kocher May 10, 2018

Hi Marcos

Yes, the workflow is published. I re-tested, added myself as reporter and assignee, removed all watchers and processed the issue through the workflow. In the transition, where the assignee is changed, I am not added as watcher. And the post function still says: "Has not run yet", so somehow it does not start.

Best regards

Peter

Suggest an answer

Log in or Sign up to answer