Hi there,
I have a Create Sub-tasks post-function that's creating 10 different sub-tasks (part of an onboarding proecess) in a Task workflow (using Bob Swift CoT). The problem is, the executor of that transition does not want to be set as a Watcher on each subsequently created Sub-Task, only the main Task.
In the Create transition of the Sub-Task workflow I have this Scriptrunner custom script post-function:
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)
}
However, the executing user of the transition on the Task is still being set as a watcher for each produced Sub-Task. Any ideas on how to get around this? Thank you so much!
-Andrew
I am not sure why you can't prevent watching from the Create transition.
I tried and even if you make the script the very last step, the current user is still the watcher.
So, short of disabling AutoWatch globally, you can add a scriptrunner script on the transition that creates the sub-tasks, and after that sub-task creation, then clear out all the watchers from all the subtask (or just the ones created in the last minute).
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def locale = ComponentAccessor.getLocaleManager().getLocaleFor(user)
def watcherManager = ComponentAccessor.getWatcherManager()
issue.subTaskObjects.each{subTask ->
def watchers = watcherManager.getWatchers(subTask , locale)
watchers.each { watcher ->
watcherManager.stopWatching(watcher, subTask )
}
}
Hi @PD Sheehan, yes I was running into that same scenario. I re-ordered it in every which way on the Create transition to no avail.
For adding it to the Create sub-task post-function on the Task, the only problem is that the post-function to create those sub-tasks is actually Bob-Swift CoT, and not Scriptrunner. Will I have to replace that functionality completely with a post-function script, in order to add the Scriptrunner script to the same post-function responsible for creating the sub-tasks?
Thanks for your quick reply.
Cheers,
Andrew
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I meant to add a custom scriptrunner post function AFTER the bob-swift post function(s) that create the subtasks.
This scriptrunner script will then remove those watchers form all the sub-tasks that will have just been created.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, I see. And would it remove watchers form any subtasks recently created in Jira altogether, or just those created from this specific transition?
I'm also looking into playing around with the executing user for each specific CoT transition. That would, in theory, work -- but it's failing to produce sub-task issuetypes when the post-functions execute as my bot user, despite proper project permissions set. (This is a whole other issue though, ha).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The example I included removes all watchers from all sub-tasks.
You would need to implement additional logic if you just want to remove watchers from the recently created sub-tasks.
Something like this for example:
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def locale = ComponentAccessor.getLocaleManager().getLocaleFor(user)
def watcherManager = ComponentAccessor.getWatcherManager()
def threshHold = use (groovy.time.TimeCategory) {2.minutes.ago.toTimestamp()}
issue.subTaskObjects.findAll{it.created >= threshHold }.each{subTask ->
def watchers = watcherManager.getWatchers(subTask , locale)
watchers.each { watcher ->
watcherManager.stopWatching(watcher, subTask )
}
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.