I have this Scriptrunner script:
import com.atlassian.jira.component.ComponentAccessor
import org.apache.log4j.Category
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
MutableIssue issue = issue
def watcherManager = ComponentAccessor.getWatcherManager();
def userManager = ComponentAccessor.getUserManager()
def user1 = userManager.getUserByKey('flaurentine')
if (issue.getReporterId() in ['machase' <and a list of other ids>])
{
watcherManager.startWatching(user1, issue)
}
-----------------------------
I get no errors when saving the script, but when I run it I get:
2018-01-04 11:07:00,157 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-01-04 11:07:00,157 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:167) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:84) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:75) at com.atlassian.jira.issue.watchers.WatcherManager$startWatching.call(Unknown Source) at Script206.run(Script206.groovy:32)
So apparently it doesn't like my watcherManager statement, but I don't know why? I've checked and user1 is what I expect it to be. By process of elimination I'm misusing "issue" but I don't know how to fix it. Please help. Thank you!
Hello,
Where do you execute the script?
you should log values to your log to be sure that issue and user1 are not null.
log.error(issue)
log.error(user1)
Then have a look at the logs.
I mean the variable issue is only available for post-function, validators and conditions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Alexey, thank you so much for answering. I put in:
log.debug(user1)
log.debug(issue)
and I get back:
2018-01-04 11:51:31,700 DEBUG [jira.groovy]: flaurentine(flaurentine) 2018-01-04 11:51:31,700 ERROR [jira.groovy]: debug
The first one is as expected, but I don't know what the other one means?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Where do you execute the script?
try log.debug(issue.key)
I am also not sure what the second line means
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The script is in a post-function on the create transition.
I took out the startWatching statement but added log.debug(issue.key) and I get this:
2018-01-04 12:18:03,426 DEBUG [jira.groovy]: flaurentine(flaurentine) 2018-01-04 12:18:03,426 DEBUG [jira.groovy]: debug 2018-01-04 12:18:03,428 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-01-04 12:18:03,429 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:167) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:84) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:75) at com.atlassian.jira.issue.watchers.WatcherManager$startWatching.call(Unknown Source) at Script281.run(Script281.groovy:34)
So I'm back to the null pointer exception, so I'm guessing that means issue is null, or at least issue.key is null. How should I be getting issue to mean "this issue that I'm creating"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your post function must be last in the list
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.