I am trying to add users as watchers during the CREATE post-function with a scriptrunner script. The following code (starting at line 236)
def usernames = ["user1", "user2", "user3"];
usernames.each {
def user = ComponentAccessor.getUserManager().getUserByName("${it}")
if (user != null) ComponentAccessor.getWatcherManager().startWatching(user, issue)
}
results in the following error message:
2018-09-11 17:26:13,177 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script> java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at com.google.common.cache.LocalCache$LocalManualCache.invalidate(LocalCache.java:4764) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.updateWatch(DefaultWatcherManager.java:172) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:89) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:80) at com.atlassian.jira.issue.watchers.WatcherManager$startWatching.call(Unknown Source) at Script203$_run_closure1.doCall(Script203.groovy:239) at Script203.run(Script203.groovy:237
I *guess* that the issue arises because the *issue* is in the process of being created and does not have all the necessary information stored at this point in time in the issue object.
Solutions from two years ago mention the deprecated method issue.getGenericValue(), but that approach seems to no longer work with WatcherManager.startWatching().
What is the preferred way of doing this?
Hi Martin,
probably you need to move your pf order. You need to move this script after "Creates the issue originally.". It should solve your issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please, mark answer as resolved accepting my suggestion.
Ciao,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Martin,
try using this code :
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.watchers.WatcherManager;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserManager;
String[] users = {"user1", "user2", "user3"};
UserManager userManager = ComponentAccessor.getUserManager();
WatcherManager watcherManager = ComponentAccessor.getWatcherManager();
for(String us : users){
ApplicationUser user = userManager.getUserByKey(us);
if(user!=null)
watcherManager.startWatching(user, issue);
}
Hope this helps,
Ciao,
Fabio
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fabio,
thank you for your suggestion. Unfortunately, that does not solve my situation:
2018-09-12 09:45:18,964 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: null, actionId: 1, file: <inline script> java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at com.google.common.cache.LocalCache$LocalManualCache.invalidate(LocalCache.java:4764) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.updateWatch(DefaultWatcherManager.java:172) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:89) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:80) at com.atlassian.jira.issue.watchers.WatcherManager$startWatching.call(Unknown Source) at Script245.run(Script245.groovy:245)
I guess the problem still lies with the issue. Is the problem related to how I define that? Line 245 is this one:
watcherManager.startWatching(user, issue);
Way up the script, there is the following line:
MutableIssue issue = issue;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Want to make your everyday Community actions directly contribute to reforestation? The Atlassian Community can achieve this goal by liking a post, attending an ACE, sending your peers kudos, and so much more!
Help us plant more trees
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.