Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,059
Community Members
 
Community Events
168
Community Groups

ScriptRunner condition to ensure only one sub-task can be created per issue

Edited

I use ScriptRunner Script Listeners and Post Funtions to create sub-tasks.

However, with this particular workflow, I need a condition that checks to see if any other sub-tasks of the same type have already been created. If they have, then I need JIRA to restrict the action to ensure that only one sub-task per sub-task type can be created.

My project has 4 different sub-task types: Order Parts, Purge Parts, Claims, and Corrective Actions. 

Can someone help me write a condition for a Script Listener and for a Post Function that checks the parent to see if a similar sub-task has already been created, and if it has restrict the action from completing.

In the end, my workflow should only allow one Order Parts sub-task, one Purge Parts sub-task, one Claims sub-task, and one Corrective Actions sub-task at any given time.

2 answers

1 accepted

1 vote
Answer accepted

Hello @Gavin Minnis

Can you provide more information?

When subtasks created?

What your behaviour do?

@Mark Markov

Sub-tasks are created at two different times: 1) Issue Create 2) Issue Update, when a field value changes either during a workflow transition (e.g. changing a value on a screen during workflow transition) or simply editing the field on the Issue View or Edit screen.

Regarding your second question, I am so glad that you asked. I didn't mean to say I was using Behaviours. I am actually using a Script Listener. The listener has a condition where it looks for the value of a field to equal "Yes" and then at those times it creates a sub-task. I have the Events for this listener set to Issue Create and Issue Update.

Hmm, I can't provide good advice to you without code examples, but here is example how you can find subtasks of issue and names

import com.atlassian.jira.component.ComponentAccessor

def subtaskToCreateName = "Task"
def issue = ComponentAccessor.getIssueManager().getIssueObject("TEST-1")
//getting subtasks names of given issue
def subtaskIssueTypes = issue.getSubTaskObjects().collect {it.getIssueType().getName()}
//checking if creating subtask alrealdy exist
if (!(subtaskToCreateName in subtaskIssueTypes)){
//your code to create subtask
}

@Mark Markov

I'm not sure what code you need to see. But for the Script Listener I have the Condition set to:

cfValues['Purge Stock']?.getValue() == 'Yes'

So when the custom field "Purge Stock" has a value of "Yes" this listener picks it up and create's a "Purge Stock" sub-task. This listener uses the Issue Create and Issue Update events. So essentially, I'm try to expand this condition so that not only will the Condition be to listen for when the custom field value is changed to "Yes" but also to ensure that there isn't already a "Purge Stock" sub-task created. Because there should only be one at a time. 

Then try this condotion

def subtaskIssueTypes = issue.getSubTaskObjects().collect {it.getIssueType().getName()}
cfValues['Purge Stock']?.getValue() == 'Yes' && !('Purge Stock' in subtaskIssueTypes)
Like Rahul Savaikar likes this

@Mark Markov

That worked! Perfect. Thanks for your help.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events