Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
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

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

0 votes
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)

@Mark Markov

That worked! Perfect. Thanks for your help.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

26 views 0 1
Read article

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