Automatically remove users from the parent watchers field

Mani November 19, 2019

Hello All,

I want remove to users from the parent watchers fields when his/her sub-tasks completed.

Is it possible?

Thanks in advance,

Manikanta

2 answers

1 accepted

0 votes
Answer accepted
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2019

Hi @Mani,

you are almost there, your current script is running for the issue on which event(transition) is happened. you just need to get it's parent object

I'm attaching updated script for your reference

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

def userManager = ComponentAccessor.getUserManager()

def watcherManager = ComponentAccessor.getWatcherManager()

if(issue.getIssueType().name == "Sub-task"){ //used to check sub-task or not if workflow is same if not you can remove this condition
def parent = issue.getParentObject() // getting parent object
ApplicationUser user = issue.getAssignee() // getting sub-tasks assignee
watcherManager.stopWatching(user, parent) // remove sub-task assignee from parent's watcher list

 NOTE: I'm just removing Done sub-tasks assignee from parent's watcher list not all

Hope it helps you

 

BR,
Leo

Mani November 20, 2019

Hi @Leo ,

Thanks for the script.

sub-task watcher is getting removed once one of the sub-task is moved to Done. But in my case assignee should be removed from the watcher field only if all sub-tasks moved to Done assigned on his/her name.

Thanks in advance,

Mani

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 20, 2019

It's little tricky, we need to iterate over all sub-tasks of parent and check the status and assignee of each, I just modified something in above script. mostly this should do the job for you

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser

def userManager = ComponentAccessor.getUserManager()

def watcherManager = ComponentAccessor.getWatcherManager()
if(issue.getIssueType().name == "Sub-task"){
def allDone = true
ApplicationUser user = issue.getAssignee()
def parent = issue.getParentObject()
parent.getSubTaskObjects()?.each { subtask ->
if(subtask.getAssignee() == user && subtask.getStatus().name != "Done" && subtask != issue)
{
allDone = false
}
}
if(allDone){
watcherManager.stopWatching(user, parent)
}
}

 

BR,

Leo

Mani November 20, 2019

Thanks a lot, It worked.

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 20, 2019

cool (y)

0 votes
Christos Moysiadis
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.
November 19, 2019

Hello @Mani ,

with the default features of the postfunction in the workflows, i am not 100% sure that you can achieve it. However, if you have scriptrunner addon installed you could implement a simple script to do this functionallity.

This link below may help you, as a guide:

https://community.atlassian.com/t5/Jira-questions/scriptrunner-how-to-clear-watchers-when-creating-subtask/qaq-p/117538

Regards
Christos

Mani November 19, 2019

Hi @Christos Moysiadis

I placed below script in the sub-task Done transition, but it is removing watchers from the sub-task issues, i want to remove watchers from the parent issue type.

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)
}

For Example - 3 sub-tasks are assigned on my name once all sub-tasks are moved to Done, my name should not be there on the parent watcher list.

Thanks in advance,

Manikanta

Suggest an answer

Log in or Sign up to answer