• Community
  • Products
  • Jira Software
  • Questions
  • I worked on filter , which has huge number of SCRs. I tried to add watchers. But wrongly deleted existing watchers. Please let me know if there is any shortcut to undo this last operation.

I worked on filter , which has huge number of SCRs. I tried to add watchers. But wrongly deleted existing watchers. Please let me know if there is any shortcut to undo this last operation.

Prasun February 19, 2016
 

1 answer

1 accepted

0 votes
Answer accepted
Vasiliy Zverev
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.
February 19, 2016

The onle advice is to restore backup on test instance and get watchers list.

If you delete watcher for several users you can do it manually. If not - I could help you to write respective script.

Prasun February 19, 2016

I had around 300 scrs. For each SCR, watcher list was different. I wrongly updated each watcher list with some fixed names. I want to revert back to old one. It will be very helpful if some methods or scripts exist.

 

Vasiliy Zverev
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.
February 19, 2016

The idea is following: 

  • we have correct watchers lists on test instance restored from back up
  • we need to copy it from test instance to prod one

Here is code to get all watchers for specified issue list:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.util.UserManager

/**
 * Created by VZverev on 20.02.2016.
 */

//create a list of issues to get watchers
List<Issue> issueList = new ArrayList<>();
issueList.add(ComponentAccessor.getIssueManager().getIssueObject("ZVER-3"))
issueList.add(ComponentAccessor.getIssueManager().getIssueObject("ZVER-4"))

UserManager userManager = ComponentAccessor.getUserManager();

//now lets find all watchers
WatcherManager watcherManager = ComponentAccessor.getWatcherManager();
StringBuilder result = new StringBuilder();
for(Issue issue: issueList) {
    result.append("list.add(new AddWatchers(" + issue.getId() + ", [")
    for (String userKey : watcherManager.getWatcherUserKeys(issue)) {
        result.append( "\"" + userManager.getUserByKey(userKey).getKey() + "\", ")
    }
    result.append("])); ")
}

return result.toString().replace(", ]", "]")

You should run it via Script Console provided ScriptRunner plugin.

As result you will get strings to user in script for add watchers. Here it is:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.watchers.WatcherManager
import com.atlassian.jira.user.util.UserManager

/**
 * Created by VZverev on 20.02.2016.
 */

List<AddWatchers> list = new ArrayList<>()
//Plave here all strings from previous script
list.add(new AddWatchers(24910, ["vzverev@phosagro.ru"]));

//Loop to add watchers
for(AddWatchers addWatchers: list){
    addWatchers.doSetWatchers();
}

class AddWatchers{
    Issue issue;
    List<String> watchersUserKeys;
    private static WatcherManager watcherManager = ComponentAccessor.getWatcherManager();
    private static IssueManager issueManager = ComponentAccessor.getIssueManager();
    private static UserManager userManager = ComponentAccessor.getUserManager();

    public AddWatchers(long _key, List<String> _users  ){
        issue = issueManager.getIssueObject(_key);
        watchersUserKeys = _users;
    }

    public doSetWatchers(){
        for(String user: watchersUserKeys)
            watcherManager.startWatching(userManager.getUserByKey(user), issue)
    }
}

I strongly reccomend you to test it ar first on test instance.

Suggest an answer

Log in or Sign up to answer