Workflow Validator

David Plesu
Contributor
February 15, 2024

Hello,

I hope you are doing well!

I would like to create an workflow validator that:

If the childes are not done, then you cannot make this transition!

And I want for all the issue types that can be a child in the epic: story, task... without bug. If is a bug and is not done you can close the epic is not a problem.

Thanks!

Regards,

David

3 answers

1 accepted

1 vote
Answer accepted
Kristian Walker _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.
February 15, 2024

Hi David,

I can confirm that to achieve your requirement, you can use the Workflow Validators feature that ScriptRunner for Jira Cloud provides to make the assignee field required on the transition screen.

Workflow validators use the Jira Expression framework provided by Atlassian, and I can confirm we have some examples here to show their syntax.

I can confirm we have an example validator here on line 72 that will help to achieve your requirements.

I hope this information helps.

Regards,

Kristian

David Plesu
Contributor
February 15, 2024

Hello,

Thank you for this documentation it helped.

Here is a final version that I used, when i have more "Done" statuses.

Maybe will help someone:

issue.isEpic && issue.stories.every(story => (
(story.issueType.name == 'Bug' && story.status.name != 'Done')
||
(story.issueType.name == 'Bug' && story.status.name == 'Done')
||
(story.issueType.name != 'Bug' && (story.status.name == 'Done' || story.status.name == 'Resolved' || story.status.name == 'Closed' || story.status.name == 'Mitigated' || story.status.name == 'Duplicate' || story.status.name == 'Defer' || story.status.name == 'Rejected'))
))

 

Regards,

David.

Kristian Walker _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.
February 16, 2024

Hi David,

I am glad we helped you to solve your requirement.

Regards,

Kristian

vaughan_dickson
Contributor
April 30, 2024

Hi Kristian your script above to prevent parent if child issues are not Done works fine for issues under a Epic parent. however we have a custom issuetupe UAT which sit on the same level as a Epic but the script "issue.isEpic" only works for issues in Epic. is there any alternative for example issue.isParent for any parent (NOT a Epic) issues?

1 vote
Mary from Planyway
Atlassian Partner
February 15, 2024

Hi @David Plesu 

It's Mary from Planyway for Jira

To create a Jira workflow validator that restricts the transition of an epic if its child issues (stories, tasks, etc.) are not done, excluding bugs, you'll need to use Jira's workflow editing capabilities. If your Jira instance has ScriptRunner installed, you can achieve this with a Groovy script. If you don't have ScriptRunner or a similar plugin, you might need to look for a plugin that offers custom workflow validation or consider writing a plugin yourself if you have development resources.

Here's a high-level approach using ScriptRunner to create a custom validator:

Step 1: Install ScriptRunner

Ensure you have ScriptRunner for Jira installed since we'll be using it to write a custom script for the validator.

Step 2: Navigate to Workflow Configuration

  1. Go to Jira settings > Issues.
  2. Select Workflows under WORKFLOWS.
  3. Find the workflow that's applied to your epics and click Edit.

Step 3: Add a Custom Script Validator

  1. Select the transition you want to restrict (e.g., from "In Progress" to "Done").
  2. Click on Validators in the transition's properties.
  3. Click Add validator.
  4. Choose Script Validator from ScriptRunner.
  5. Click Add.

Step 4: Script Configuration

You'll need to write a Groovy script that checks if all child issues (excluding bugs) are in a "Done" status. Here's an example script that you might use or adapt:

import com.atlassian.jira.component.ComponentAccessor

def issueLinkManager = ComponentAccessor.issueLinkManager
def subTaskManager = ComponentAccessor.subTaskManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser

def epicLinkField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Epic Link" }
def epicLink = issue.getCustomFieldValue(epicLinkField)

// Get all linked issues and sub-tasks
def linkedIssues = issueLinkManager.getLinkCollection(issue, currentUser).allIssues
def subTasks = issue.subTaskObjects

// Filter out bugs and check statuses
def nonDoneIssues = linkedIssues.findAll {
it.issueType.name != "Bug" && it.statusObject.name != "Done"
} + subTasks.findAll {
it.issueType.name != "Bug" && it.statusObject.name != "Done"
}

return nonDoneIssues.isEmpty()

Step 5: Configure Error Message

Set an appropriate error message that will be displayed to the user if the validation fails, such as "All child issues must be in 'Done' status to transition this epic, except for bugs."

Step 6: Publish the Workflow

After adding and configuring the validator, make sure to publish the workflow so your changes take effect.

This script checks all linked issues and sub-tasks of the current issue (assuming it's an epic) to see if they are in the "Done" status, excluding bugs. Adjust the script as necessary to fit your exact field names and statuses.

Kristian Walker _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.
February 15, 2024

Hi Maria 

Your solution is for Jira Server / DC and will not work in Jira Cloud as validators use the Jira Expression Framework and not Groovy in Jira Cloud.

I hope this helps.

Kristian 

0 votes
Maciej Dudziak _Forgappify_
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.
April 23, 2024

Hi,

If you are looking for a wizzard-like solution, we've developed the Linked Issues Validator available as part of the Workflow Building Blocks for Jira app. With a wizard-like UI, you can select options that represent your case. You can choose relations from: sub-tasks, parent issues, epic children, and linked issues. Additionally, you can filter relations by issue types and select criteria based on status category and status.

In your case it would be similar to the following:

community_23.04_children.png

If you want to test all children issue types except "Bug", then under "Issue types", select all issue types except "Bug."

I am from Forgappify, the vendor of the app.

I hope it will help.

Cheers

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events