Logic to not create sub-tasks in a transiton if the sub-tasks are already created

Kalpana Ramesh August 18, 2016

Hi, in my workflow, there are multiple statuses going to On Hold.

  • "On hold" status can only be reached from New or Preparation and Analysis state. 

    Note - "Send for analysis" is the transition between New or Preparation and Analysis state as well as On Hold to Preparation and Analysis

  • On “send for analysis” transition from On hold status to Preparation and Analysis status, a new logic is required to not create sub-tasks if the sub-tasks are already created.

How can this be achieved?


Thank you!

 

 

2 answers

1 accepted

0 votes
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 18, 2016

How are you creating the new sub-tasks?  If it's a post-function to create them, I'm afraid you'll probably have to replace it with something more clever - something that executes a search for existing sub-tasks before it creates anything.

Kalpana Ramesh August 22, 2016

Hi.

I reused transition containing the post function that creates the subtasks while moving from On Hold to Preparation and Analysis.While doing so, the subtasks are getting created twice. I would like to know if there could be a condition passed on as while creating the subtask to check if there is an existing subtask already.

Thank you.

 

 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 22, 2016

Same answer - you'll need to replace those post-functions with others with more code in them, code that can detect the existing sub-tasks and exit before creating the duplicates.

Or duplicate the transition and have one that has conditions saying "only if no subtasks exist" and the other one with a condition of "subtasks must exist".  Again, you'll need a bit of code for them

Kalpana Ramesh August 22, 2016

I am kind of stuck at this place. Could you guide me on what code has to be used to carry it out? 

I am using the following code but the sub tasks aren't getting created.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.issuetype.IssueType
 
if (issue.issueTypeObject.name == 'iType') { 
    IssueType issueType = ComponentAccessor.getConstantsManager().getIssueTypeObject("5"); //Since my subtask is Sub-Task
        for(subTask in issue.getSubTaskObjects()) {
            if(subTask.getIssueTypeObject().equals(issueType)) {
                return false;
           }
        } 
    return true;
}
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
August 23, 2016

You're comparing strings in the if statement, so it should be

if ("iType".equals(issue.issueTypeObject.name) )

 

Rest of it looks ok at a glance.

0 votes
vitaliy zapolskyy
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.
August 23, 2016

try to add 2 transitions for On Hold to Preparation and Analysis having mutually exclusive conditions based on sub-tasks count.

this way user will see only one of the two transitions.


Suggest an answer

Log in or Sign up to answer