Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Thanks, but it was too late.
My working code:
post("/rest/api/3/issue/${issue.key}/watchers")
.header('Content-Type', 'application/json')
.body('"<accountId>"')
.asString()
Hi VVeider,
Thank you for your question.
I can confirm that as Randy has said that to add a watcher with ScriptRunner for Jira Cloud that you will need to make a rest API call to the watchers API.
I can confirm that we have an example code snippet located here which can be run in the Script Console and shows how you can set the watcher on an Issue and that you will be able to take this example and modify it to create the post function that you require.
I can confirm that inside the post function that there is a variable called issue which comes in the binding of the script and you can get the issue key to pass into the rest call by calling issue.key.
Finally, I can advise that if you are creating your post function on the Create transition that the post function should be ordered as the last post function in the list of post functions, so that the issue is created before the post function code is executed.
If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.
Regards,
Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kristian thanks for this post https://bitbucket.org/snippets/Adaptavist/yAdX6X?_ga=2.267944206.120189328.1585505760-1987078914.1573938112
Since October I was trying to solve this problem.
This is my code to automatically add watchers from a certain JIRA group to a newly created Incident issue:
def issueKey = issue.key
def group = get('/rest/api/3/group/member')
.header('Content-Type', 'application/json')
.queryString("groupname":"IT Department")
.asObject(Map)
.body
group.values.accountId.each{accountId->
def result = post('/rest/api/2/issue/' + issueKey + '/watchers')
.header('Content-Type', 'application/json')
.body("\"${accountId}\"")
.asString()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
post("/rest/api/3/issue/{issueKey}/watchers/")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Randy. Thanks.
But:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. you only need to include post body contents if the watcher you're setting is different from the executing user.
2. This is a different issue from your original question but when you submit a create request the call will return the issuekey. You cant run post functions on create transition reliably unfortunately, use a listener instead and there will be an issue binding available.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.