Skip to main content
Book your demo
Example scripts
To homepage
Jira
Cloud icon
Cloud

Add the current user as a watcher

Features
Listeners
Created 6 month(s) ago, Updated 6 day(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