Validation on Siblings Sub-tasks

Vinay Shekar February 19, 2016

Below is my requirement. Let me know how can we achieve this.

Parent Issue has 3 sub-tasks say A,B,C.
A,B follows workflow (Open --> In Progress --> Resolved)
C follows workflow (Open --> Approved --> Resolved)

I need to add validation for sub-tasks C where it can be Approved only when sibling sub-tasks A and B are in status Resolved.

Let me know for any clarification.

Thanks
Vinay

3 answers

1 accepted

0 votes
Answer accepted
Bob Swift OSS (Bob Swift Atlassian Apps)
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.
February 19, 2016

You can add a Conditioned validator (from Update on Transition for JIRA) that uses a JQL query to determine the condition to proceed. Here is a how-to: 

1 vote
JamieA
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.
February 22, 2016

This was also created as a support request so I will add my answer also:

You probably want a condition rather than a validator. Add the condition to the Approve transition only of issue type C.

You can use a "Simple Scripted Condition" with the following code:


{code}
def parent = issue.parentObject
def otherSubtasks = parent.subTaskObjects.findAll { it.issueTypeObject.name in ["A", "B"]}
return otherSubtasks.every {
    it.statusObject.name == "Resolved"
}
{code}

Update the A, B issue type names as necessary.

JamieA
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.
February 22, 2016

CQ is so broken today, |I give up trying to get the formatting right.

Amy Niebel August 20, 2018

I'm getting a deprecation error with "issueTypeObject" but can't seem to find an equivalent solution using "getIssueType", which is what's recommended.

To top it off, the Developer's page says that "getIssueType" has been deprecated but to use "issueTypeObject". 

Curious if this is the most recent and just getting incorrect errors or if I'm misunderstanding the Developer documentation?

0 votes
Boris Georgiev _Appfire_
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.
February 19, 2016

You can write a scripted condition/validator which should look like the one below (might need a few corrections, but will give you an idea)

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.opensymphony.workflow.WorkflowContext;
import com.atlassian.jira.config.SubTaskManager
import com.atlassian.jira.workflow.WorkflowTransitionUtil;
import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl;
import com.atlassian.jira.util.JiraUtils;
import com.atlassian.jira.issue.status.Status
 
def areDependentSubTasksResolved(Issue issue) {
    SubTaskManager subTaskManager = ComponentAccessor.getSubTaskManager();
    Collection subTasks = issue.getSubTaskObjects();
 
    if (subTasks.isEmpty())
        return false;
 
    for (currIssue in subTasks)
    {
        if (currIssue.issueTypeObject.name == "ABType" && currIssue.getStatusObject().name != "Resolved")
            return false;
 
    }
 
    return true;
 
}
if(issue.issueTypeObject.name  == 'CTask') {
	return areDependentSubTasksResolved(issue.parentObject));
}
return true

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events