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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,558,752
Community Members
 
Community Events
184
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
Mark Markov
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 Leaders.
Jul 30, 2018

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.

Mark Markov
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 Leaders.
Jul 30, 2018

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. 

Mark Markov
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 Leaders.
Jul 30, 2018

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
AUG Leaders

Atlassian Community Events