Skip to main content
Example scripts
arrow icon
To homepage
New
Jira
Cloud icon
Cloud

Add the current user as a watcher

Features
Listeners
Created 1 month(s) ago, Updated 1 month(s) ago
App in script
ScriptRunner For Jira
ScriptRunner For Jira
by Adaptavist
Compatibility
compatibility bullet
Jira
Language |
groovy
final issueKey = issue.key
def currentUser = Users.getLoggedInUser()

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

if (watcherResp.status == 204) {
    logger.info("Successfully added ${currentUser.displayName} as watcher of ${issueKey}")
} else {
    logger.error("Error adding watcher: ${watcherResp.body}")
}
Having an issue with this script?
Report it here