I've created a Script Post-Function [ScriptRunner] Function that automatically creates Sub-tasks when a New issue is created in the project.
Now, I want to apply a condition that will only create those Sub-tasks when a specific custom field is set to a specific value, i.e., Project Type (Custom Field) == Project Initiative (dropdown menu option).
Any help would be greatly appreciated!
You can use this scripted post-function to remove all watchers from an issue:
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def locale = ComponentAccessor.getLocaleManager().getLocaleFor(user)
def watcherManager = ComponentAccessor.getWatcherManager()
def watchers = watcherManager.getWatchers(issue, locale)
watchers.each { watcher ->
watcherManager.stopWatching(watcher, issue)
}
I put your scripted post-function as the last post-function in the sub-task create workflow. Didn't work. I'm assuming, perhaps incorrectly, that the sub-task create transition invoked from the parent workflow executes the post-functions that exist in the sub-task create workflow. Or does it not?
I then tried putting it in the sub-task create transition in the parent workflow and received the following error:
[c.o.s.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: IS-10597, actionId: 911, file: null java.lang.NullPointerException at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:210) at com.google.common.cache.LocalCache.get(LocalCache.java:3936) at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3941) at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4824) at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4830) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.getWatcherUserKeys(DefaultWatcherManager.java:159) at com.atlassian.jira.issue.watchers.DefaultWatcherManager.getWatchers(DefaultWatcherManager.java:136) at com.atlassian.jira.issue.watchers.WatcherManager$getWatchers$0.call(Unknown Source) at Script47.run(Script47.groovy:11)
The sub-task create workflow now looks like this:
def cf = customFieldManager.getCustomFieldObjects(sourceIssue).find {it.name == 'Product Name'}
issue.summary = sourceIssue.getCustomFieldValue(cf)
issue.summary = issue.summary + " - License"
issue.description = "";
checkLink = {link -> false};
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def locale = ComponentAccessor.getLocaleManager().getLocaleFor(user)
def watcherManager = ComponentAccessor.getWatcherManager()
def watchers = watcherManager.getWatchers(issue, locale)
watchers.each { watcher ->
watcherManager.stopWatching(watcher, issue)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To be clear, I don't want to clear the watchers from the parent issue, but from the newly created sub-task.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the sub-task, I added a "clear watchers" transition that only calls your code and it works like a charm. It's a couple more steps (have to go into the sub-task, etc) but better than nothing!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great, glad its working for you. Yeah sticking it on the create transition for the sub-task will work.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Putting it in the create transition for the sub-task did not work. I just have a New -> New transition called "Clear Watchers" and all it does is run your script.
But it does exactly what I need. So thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
watchers.each { watcher ->
watcherManager.stopWatching(watcher, issue)
Hello!
i have an error in this place:
The script could not be compiled: <pre>org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script19.groovy: 6: expecting '}', found '-' @ line 6, column 25. watchers.each { watcher -> ^ 1 error </pre>.
Added a Custom script post-function (scriptrunner).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Solution: need to change ">" to ">".
Thank`s a lot to cool guys from the telegram`s chat of Atlassian Community!
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.