Forums

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

How can I prevent a task from being set to 'Done', while keeping the button visible

Ivan
Contributor
December 16, 2024

Hello community,

In my topic, I want to configure the system so that it’s not possible to set an open task to the status "Done" or "Canceled" if there are still open subtasks.

I know that under the "Triggers" section, you can set the transition to "All subtasks must be done," but here’s the actual problem:

I don’t want the "Done" button to disappear. Instead, I want it to remain visible, and when I click it, there should be a message like "Check open subtasks," for example.

How can I set this up? Does anyone have an idea?

 

(Info --> "Erledigt" = "Done")

Screenshot 2024-12-16 091413.png

Screenshot 2024-12-16 091151.png

Screenshot 2024-12-16 091434.png

3 answers

2 accepted

4 votes
Answer accepted
Tuncay Senturk
Community Champion
December 16, 2024

Hi @Ivan 

To achieve this in Jira, you can use a Workflow Validator instead of a Trigger or a condition. A Workflow Validator allows you to check conditions when transitioning an issue, and if the condition isn’t met, it displays an error message while keeping the transition button visible. Workflow condition hides the button when it does not meet the condition.

2 votes
Answer accepted
Cyrille Martin
Community Champion
December 16, 2024

Hi @Ivan 

You can use the Condition on your workflow to do exactly the behavior you explained

Here is the documentation

Sorry not the Condition, but the Validators.

Regards,

2 votes
Ivan
Contributor
December 16, 2024

Hei, @Tuncay Senturk @Cyrille Martin 

thank you guys for the quick answer, but what option should I choose in the Validators option?

Do I have to run my own script and choose the "Custom Script validator"?

Tuncay Senturk
Community Champion
December 16, 2024

Edit your workflow and select the transition to the "Done" or "Canceled" status (for example, the transition from "In Progress" to "Done")

Then click on the transition arrow and select Validators.

Add Validator, then select ScriptRunner > Script Validator (I assume you have ScriptRunner)

Use the following Groovy script to check for unresolved subtasks. Please adjust the code to your needs and test it

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def subTaskManager = ComponentAccessor.getSubTaskManager()

if (issue.isSubTask()) {
return true
}

def subTasks = issue.getSubTaskObjects()

// Check if any subtask is not in the "Done" status
if (subTasks.any { it.getStatusObject().getName() != "Done" }) {
invalidInputException.addErrorMessage("You cannot transition this issue to 'Done' or 'Canceled' while it has open subtasks.")
return false
}

return true

 

Like Stephen_Lugton likes this
Ivan
Contributor
December 16, 2024

Thank you so much, I tried it with your script and now it works perfectly fine. I already testes it and now I know how to do it by my own. Thank you @Tuncay Senturk !!

Ivan
Contributor
December 18, 2024

Hei @Tuncay Senturk Sorry for bothering you again, but how do I rewrite the script so that not only the sub-task is checked, but also the task "Genehmigungsaufgabe"?

 

genehmigung.png

Ivan
Contributor
December 18, 2024

seems liked It worked now with this one:

 

Ivan
Contributor
December 18, 2024

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def subTaskManager = ComponentAccessor.getSubTaskManager()

// Prüfen, ob das aktuelle Issue ein Sub-Task ist → Kein Check nötig
if (issue.isSubTask()) {
return true
}

// Alle Sub-Tasks abrufen
def subTasks = issue.getSubTaskObjects()

// 1. Filtern nach Sub-Tasks vom Typ "Genehmigungsaufgabe"
def approvalTasks = subTasks.findAll { it.getIssueType().getName() == "Genehmigungsaufgabe" }

// Prüfen, ob eine "Genehmigungsaufgabe" noch im Status "Open" ist
if (approvalTasks.any { it.getStatusObject().getName() == "Open" }) {
invalidInputException.addErrorMessage("You cannot close this issue while any 'Genehmigungsaufgabe' is still in the 'Open' status.")
return false
}

// 2. Prüfen, ob alle Sub-Tasks (außer Genehmigungsaufgaben) im Status "Done" sind
def remainingSubTasks = subTasks - approvalTasks // Sub-Tasks ohne "Genehmigungsaufgabe"
if (remainingSubTasks.any { it.getStatusObject().getName() != "Done" }) {
invalidInputException.addErrorMessage("You cannot close this issue while some subtasks are not in the 'Done' status.")
return false
}

return true

Tuncay Senturk
Community Champion
December 18, 2024

Please double-check. 

 

import com.atlassian.jira.component.ComponentAccessor

def issueManager = ComponentAccessor.getIssueManager()
def subTaskManager = ComponentAccessor.getSubTaskManager()


// Get the issue type of the current issue
def issueTypeName = issue.getIssueType().getName()

// Check if the current issue is of type "Genehmigungsaufgabe"
if (issueTypeName == "Genehmigungsaufgabe") {
// Check if the current "Genehmigungsaufgabe" issue is in the "Open" status
if (issue.getStatusObject().getName() == "Open") {
invalidInputException.addErrorMessage("This 'Genehmigungsaufgabe' cannot be closed while it is in the 'Open' status.")
return false
}
}

// If the issue is not a sub-task, check its sub-tasks
if (!issue.isSubTask()) {
// Alle Sub-Tasks abrufen
def subTasks = issue.getSubTaskObjects()

// 1. Filtern nach Sub-Tasks vom Typ "Genehmigungsaufgabe"
def approvalTasks = subTasks.findAll { it.getIssueType().getName() == "Genehmigungsaufgabe" }

// Prüfen, ob eine "Genehmigungsaufgabe" noch im Status "Open" ist
if (approvalTasks.any { it.getStatusObject().getName() == "Open" }) {
invalidInputException.addErrorMessage("You cannot close this issue while any 'Genehmigungsaufgabe' sub-task is still in the 'Open' status.")
return false
}

// 2. Prüfen, ob alle Sub-Tasks (außer Genehmigungsaufgaben) im Status "Done" sind
def remainingSubTasks = subTasks - approvalTasks // Sub-tasks excluding "Genehmigungsaufgabe"
if (remainingSubTasks.any { it.getStatusObject().getName() != "Done" }) {
invalidInputException.addErrorMessage("You cannot close this issue while some sub-tasks are not in the 'Done' status.")
return false
}
}

// If all checks pass, allow the transition
return true

 

Ivan
Contributor
December 18, 2024

Works perfectly fine, thank you so much!! 

Suggest an answer

Log in or Sign up to answer