Forums

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

Jira Cloud: How to add watchers in the Create transition

Amir Katz (Outseer)
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 8, 2021

I have followed the example given in this thread:

https://community.atlassian.com/t5/Jira-questions/ScriptRunner-for-Jira-Cloud-Add-watcher-in-ScriptRunner-Post/qaq-p/1177008

which points to this example:

https://bitbucket.org/snippets/Adaptavist/yAdX6X?_ga=2.267944206.120189328.1585505760-1987078914.1573938112

I created a ScriptRunner script and added it as a post-function on the Create transition, and I get error 404 below.

When I run the watchers REST API from a browser (after the ticket was created), it succeeds.

I suspect that the problem is that the issue is not yet in the database and hence the 404.

Can someone suggest another way to add watchers in the Create transition?

Thanks

2021-08-08 10:33:37.625 INFO - POST /rest/api/2/issue/IMR-262/watchers asString Request Duration: 398ms
2021-08-08 10:33:37.626 WARN - POST request to /rest/api/2/issue/IMR-262/watchers returned an error code: status: 404 - Not Found
body: {"errorMessages":[],"errors":{}}  

 Code:

def issueKey = issue.key

["john.doe@example.com", "j.l.picard@enterprise.gov"].each { accountId ->

def result = post('/rest/api/2/issue/' + issueKey + '/watchers')
.header('Content-Type', 'application/json')
.body("\"${accountId}\"")
.asString()

}

 

1 answer

1 accepted

5 votes
Answer accepted
Alex Koxaras -Relational-
Community Champion
August 8, 2021

Hi @Amir Katz (Outseer) ,

Instead of using script runner you could:

  • Use automation to add watchers on issue create
  • If you have JMWE use the Set Value Field post functions, which allows you to add watchers (if the watchers are known)
  • Without an app, you could populate custom multiple user field with the watchers name, and then choose the Copy From Value native post function to copy the values to the watcher fields

Hope all the above helps :)
Alex

Amir Katz (Outseer)
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 8, 2021

Thanks a lot!

We do have both ScriptRunner and JMWE, but the automation is no-code, which is certainly tempting.

The 3rd option - this is a migration from server to cloud, so I don't want to burden my users with additional fields.

Update: Just implemented it with automation - easy-peasy!

Will not check JWME option at this time...

Alex Koxaras -Relational-
Community Champion
August 8, 2021

Noice!

Suggest an answer

Log in or Sign up to answer