Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Automatically remove users from the parent watchers field

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 Nov 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

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 Nov 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

Thanks a lot, It worked.

Leo Community Leader Nov 20, 2019

cool (y)

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

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you