Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to Block Subtask Transition Until the Previous Subtask is Done

Bhavikaa February 6, 2025

Hi Everyone,

We have a set of subtasks and need to enforce a sequential flow, ensuring that the next subtask cannot transition until the previous one is marked as Done.

Is there a way to achieve this using Jira Cloud’s native functionality or automations?

Would appreciate any suggestions or alternative approaches to handle this use case.

Thanks,

Bhavikaa

3 answers

2 accepted

0 votes
Answer accepted
Bhavikaa February 19, 2025

Hi All,

I successfully achieved this use case using the JMWE scripted validator. Sharing the steps and script below for reference in case anyone is looking for a similar solution.

Step 1: Identify the "Previous" Subtask
Define what qualifies as the "previous" subtask. In this case, I used the subtask ID to establish the order.

Step 2: Add a "Scripted (Jira Expression)" Validator
1. Navigate to the subtask workflow in Jira Cloud.
2. Select the transition you want to restrict (e.g., "In Progress," "Done," etc.).
3. Go to Validators → Click Add Validator.
4. Choose "Build-your-own Validator (JMWE app)".
5. Use the following Jira Expression:

// Ensure the issue has a parent (i.e., it's a subtask)
issue.parent &&
(
(subtasks => {
// Sort subtasks by numeric ID
let sortedSubtasks = subtasks.sort((a, b) => Number(a.id) - Number(b.id));
// Get a list of subtask IDs in sorted order
let subtaskIds = sortedSubtasks.map(s => s.id);
// Find the index of the current subtask
let index = subtaskIds.indexOf(issue.id);
// Allow the first subtask OR ensure the previous subtask is "Done"
return index == 0 || (index > 0 && sortedSubtasks[index - 1].status.name == "Done");
})
(issue.parent.subtasks) // Correctly reference the subtasks of the parent issue
)

Let me know if you have any questions.

Thanks!

0 votes
Answer accepted
Bhavikaa February 19, 2025

Hi All,

I successfully achieved this use case using the JMWE scripted validator. Sharing the steps and script below for reference in case anyone is looking for a similar solution.

Step 1: Identify the "Previous" Subtask
Define what qualifies as the "previous" subtask. In this case, I used the subtask ID to establish the order.

Step 2: Add a "Scripted (Jira Expression)" Validator
1. Navigate to the subtask workflow in Jira Cloud.
2. Select the transition you want to restrict (e.g., "In Progress," "Done," etc.).
3. Go to Validators → Click Add Validator.
4. Choose "Build-your-own Validator (JMWE app)".
5. Use the following Jira Expression:

// Ensure the issue has a parent (i.e., it's a subtask)
issue.parent &&
(
(subtasks => {
// Sort subtasks by numeric ID
let sortedSubtasks = subtasks.sort((a, b) => Number(a.id) - Number(b.id));
// Get a list of subtask IDs in sorted order
let subtaskIds = sortedSubtasks.map(s => s.id);
// Find the index of the current subtask
let index = subtaskIds.indexOf(issue.id);
// Allow the first subtask OR ensure the previous subtask is "Done"
return index == 0 || (index > 0 && sortedSubtasks[index - 1].status.name == "Done");
})
(issue.parent.subtasks) // Correctly reference the subtasks of the parent issue
)


Let me know if you have any questions.

Thanks!

0 votes
Vishal Biyani
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 6, 2025

@Bhavikaa 

How do you define the sequence of sub-tasks?

is that stored in some custom field?

Bhavikaa February 6, 2025

Hi @Vishal Biyani ,

We have a predefined set of subtasks for different scenarios, which are created automatically via automation. Currently, we are not using any custom field to define the sequence; instead, the sequence is based on the issue key.

Would you recommend using a custom field to store the sequence, or is there a better approach?

Thanks.

Vishal Biyani
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 6, 2025

@Bhavikaa 

this will be tricky to implement. Can you refer to this article and see if this helps you get started?

 

Bhavikaa February 10, 2025

@Vishal Biyani , 

Thanks for sharing this article. I’ve already gone through it, but it doesn’t serve our purpose since we want to completely prevent/hide the transition in all other subtasks until the previous one is marked as Done.

Let me know if you have any other suggestions or workarounds to achieve this use case.

Thanks,

Bhavikaa

Suggest an answer

Log in or Sign up to answer