Forums

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

Add watcher to issues by bulk operation

Paul van Erp February 26, 2019

By a bulk operation I'd like to add a watcher to a list of issues.
It seems I can only add myself as watcher to this list.
Is there a way to add others than myself?

1 answer

0 votes
Jamil Rahimov
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.
March 15, 2019

@Paul van Erp You can use this script:
Just follow this steps:
~First change user and user2 (user2 is watcher)
~Second change query (JQL)
//-----------------------------------------------------------------------------------------------

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.user.ApplicationUser

def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def issueManager = ComponentAccessor.getIssueManager()

def userManager = ComponentAccessor.getUserManager()
//EDIT THIS USER
def user = userManager.getUserByName("jamil.rahimov")

// Edit this query to suit
def query = jqlQueryParser.parseQuery("project = SD AND issuetype = \"Service Request\" AND status = \"In Progress\"")

def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())

log.debug("Total issues: ${results.total}")


//TYPE WATCHER ID FOR ADDING TO THE ISSUE
ApplicationUser user2 = userManager.getUserByName("admin")

def watcherManager = ComponentAccessor.getWatcherManager()

results.getIssues().each {documentIssue ->
log.debug(documentIssue.key)

// if you need a mutable issue you can do:
def issue = issueManager.getIssueObject(documentIssue.id)

if (user2)
watcherManager.startWatching(user2, issue)

}

Suggest an answer

Log in or Sign up to answer