Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner Listeners - Delete subtasks based on updated custom field value

craig rayner
May 22, 2018

Hi,

 

I've created a listener to create subtasks based on a custom field radio button (Testing Required = Yes). using the built in 'create a subtask' listener. I would now like to create a listener for the opposite requirement of deleting subtasks when custom field radio button (Testing Required = No)

I'm very nooby to all of this so i've been trying to use the built in listeners as much as possible. Is this possible to do and if not is there already a solution out there?

Edit: I've found the following code, how could i edit this to do the job i want?

 

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.event.type.EventDispatchOption

// for JIRA v6.*
def user = ComponentAccessor.getJiraAuthenticationContext().user.directoryUser


// for JIRA v7.*// def user = ComponentAccessor.getJiraAuthenticationContext().userdef issueManager = ComponentAccessor.getIssueManager()

// will return a Collection<Issue> with all the subtasks of the current issue

def subTasksList = issue.getSubTaskObjects()

for (subTask in subTasksList) {    

// add a condition here if you DO NOT want to delete all the sub-tasks    

issueManager.deleteIssue(user, subTask, EventDispatchOption.ISSUE_DELETED, false)}

 

 

 

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
miikhy
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 Champions.
June 27, 2018

Hi Gabriel,

The static part of the error might be the reason here. Have you tried getting an instance of project manager instead of accessing it in a static way?

ProjectManager pm = ComponentAccessor.getProjectManager()  

then using pm object on the same method?

Cheers

Gabriel MOSCALU
June 27, 2018

Thanks!

After changing to :

import com.atlassian.jira.component.ComponentAccessor
[....]
ProjectManager pm = ComponentAccessor.getProjectManager()
Project selectedProjectObj = pm.getProjectByCurrentKeyIgnoreCase(selectedOption)

I no longer have the error!

 

Can you also help with the last issue i have?  The "${actors.getUsers()*.name}" resolves all the way down to the users that are members of the group, while i want to only get the group object...

Gabriel MOSCALU
June 27, 2018

Thanks!

 

After changing to :

 

import com.atlassian.jira.component.ComponentAccessor
[...]
ProjectManager pm = ComponentAccessor.getProjectManager()
Project selectedProjectObj = pm.getProjectByCurrentKeyIgnoreCase(selectedOption)

 

I no longer have the error!

 

Can you also provide a hint on how to get the project role group ? the "${actors.getUsers()*.name}" resolves all the way down to the actual users, and i only want the group object (to be added on the CF "Available groups")

0 votes
Gabriel MOSCALU
June 27, 2018

do you have any suggestion on how to get the group defined on project role?

The "${actors.getUsers()*.name}" resolves all the way down to the actual group members... and i need to add the group to the "Available groups" group picker CF...

miikhy
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 Champions.
June 27, 2018

Hi again!

I'd go with https://docs.atlassian.com/software/jira/docs/api/7.1.8/com/atlassian/jira/security/roles/DefaultRoleActors.html#getRoleActorsByType-java.lang.String-

That would allow you to retrieve Group type actors and you can iterate on the set returned to get group names. The String to filter on groups is defined here:

https://docs.atlassian.com/software/jira/docs/api/7.1.8/com/atlassian/jira/security/roles/ProjectRoleActor.html

Should be ProjectRoleActor.GROUP_ROLE_ACTOR_TYPE :)

Hope this helps!

Cheers

0 votes
Gabriel MOSCALU
June 27, 2018

Confirmed!

TAGS
AUG Leaders

Atlassian Community Events