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().user
def 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)
}
You could try a custom script listener, listening for an Issue Updated event and the script can be something like
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
def issue = issue as MutableIssue
def issueManager = ComponentAccessor.issueManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def radioButtonValue = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).find {it.name == "RadioButtons"}?.getValue(issue)?.value
if (radioButtonValue == "No" && !issue.isSubTask()) {
issue.getSubTaskObjects()?.each {
issueManager.deleteIssue(currentUser, it, EventDispatchOption.ISSUE_DELETED, false)
}
}
Regards, Thanos
Hi Thanos,
I'm having a couple of issues with the code above, as it produces the following errors:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is safe to ignore this error. Is because the issue variable is bound to the triggered event. The static type checking is not that clever :)
Give it a go ....
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Thanos Batagiannis [Adaptavist],
I've been using your code mentioned above and it has been a great success, although i need to make 1 slight change. Instead of deleting ALL subtasks, how would i go about specifying only deleting subtasks that begin with the word 'Test *'
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Craig,
I suppose by begin with, you mean the summary. In that case, line 12 should be
issue.getSubTaskObjects()?.findAll {it.summary.startsWith("Test ")}?.each {
issueManager.deleteIssue(currentUser, it, EventDispatchOption.ISSUE_DELETED, false)
}
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.
Hey Craig,
This should definitely be possible, especially given that you've already implemented the opposite scenario.
In theory all you should have to do, is on the condition where you check that the custom field radio is "Yes", use the same code, but change the condition check to "No".
If your happy to reply with your code for the first solution I'd be happy to show you how to make that change :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your reply. For the first example i used a scriptrunner built-in listener to create a subtask based on the radio button being updated to yes. Although, there is no built-in listener for the delete.
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.