Conditions Tutorial
Before you start this tutorial, make sure you've read the Workflow Functions Tutorial page to understand what workflow functions are, for an overview of ScriptRunner workflow functions, and for details on how to access workflow functions.
For this tutorial, we assume you already have basic knowledge of how Jira workflow functions work.
What is Great Adventure?
Great Adventure is the fictitious company we use to help provide use cases and examples of concepts covered. Great Adventure has the same problems and issues faced by most companies and needs to automate more of their processes using ScriptRunner.
Overview of ScriptRunner workflow conditions
A condition checks to make sure that a requirement has been met before you can see the next workflow transition. For example, you can add a ScriptRunner workflow condition that checks all subtasks have a set resolution before the parent task can be transitioned. Depending on what your organization requires, you may want to use workflow conditions provided by ScriptRunner. These conditions allow you to do more in your workflow, providing extra control or information. ScriptRunner includes built-in conditions that you can use right away, but you can also create your own Simple scripted condition. For a full list of our conditions, check out the available ScriptRunner workflow conditions.
Navigate to ScriptRunner workflow conditions
You can add a ScriptRunner condition to a workflow transition as follows:
Examples of ScriptRunner workflow conditions
Below are some easy-to-follow examples that will help you understand how ScriptRunner workflow conditions work.
Built-in ScriptRunner workflow condition examples
All sub-tasks must be resolved condition
In addition, when issues in this project are transitioned to Done, make sure the Resolution automatically sets to the required state (in this case Done) using a post-function. This post-function is normally already set in most sample project workflows; see the Jira Knowledge Base article on Resolutions for more information.
Great Adventure has an onboarding process that requires several steps for a new team member's first day. Those steps are all represented as sub-tasks for the onboarding issue and include: meeting with the manager, attending company orientation, setting up their workstation, and updating their calendar. Great Adventure want to make sure all onboarding sub-tasks have a Resolution of Done before a new team member can mark their onboarding as complete. They can accomplish this by adding the All sub-tasks must be resolved condition to the transition.
You can now test to see if this workflow condition works.
User in field(s) condition
Great Adventure has been having issues with some team members who have started working on issues that are not assigned to them. Great Adventure want to make sure only the team member assigned to an issue can move it from To Do to In Progress. They can accomplish this by adding the User in field(s) condition to the transition that leads from To Do to the In Progress status.
You can now test to see if this workflow condition works.
You could expand on this example and make sure a user can't move the issue directly to Done by adding the Checks if this issue has been in a status previously condition.
Scripted ScriptRunner workflow condition examples
All QA sub-tasks must be resolved - Simple scripted condition
Before you start this example, make sure you have a suitable workflow that includes a transition from To Do to In Progress or similar.
In addition, when issues in this project are transitioned to Done, make sure the Resolution automatically sets to the required state (in this case Done) using a post-function. This post-function is normally already set in most sample project workflows; see the Jira Knowledge Base article on Resolutions for more information.
Great Adventure want to make sure all QA tasks, for validating an issue, have been resolved before the issue can be moved to In Progress. As this is a more specific requirement Great Adventure need to use a Simple scripted condition instead of the All sub-tasks must be resolved condition.
You can now test to see if this workflow condition works.
You could expand on this example and make sure a user can't move the issue directly to Done by adding the Checks if this issue has been in a status previously condition.
All linked issues must be resolved - Simple scripted condition
In addition, when issues in this project are transitioned to Done, make sure the Resolution automatically sets to the required state (in this case Done) using a post-function. This post-function is normally already set in most sample project workflows; see the Jira Knowledge Base article on Resolutions for more information.
Great Adventure is having problems with issues being marked as Done when they still have other issues, linked as blockers, that are still In Progress. If an issue is blocked by any other issue, Great Adventure want to make sure that the issue with blockers cannot be transitioned to Done until all blockers are resolved. As this is a more specific requirement Great Adventure need to use a Simple scripted condition instead of the All sub-tasks must be resolved condition.
You can now test to see if this workflow condition works.