Post Functions 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 post functions
A post function is a workflow function that performs automated actions after an issue transitions to a new status. For example, you can add a ScriptRunner post function to an issue that adds a comment to specific linked issues when an issue is transitioned. Every Jira issue has some essential post functions that you can neither remove nor edit, but you can add additional post functions to your workflows. Depending on what your organization requires, you may want to use ScriptRunner post functions. ScriptRunner post functions allow you to do more in your workflow, providing extra control or information. ScriptRunner includes built-in post functions that you can use right away, but you can also create your own Custom script post-function. For a full list of our post functions, check out the available ScriptRunner workflow post functions.
Custom script post function
A ScriptRunner Custom script post-function requires some Groovy scripting but allows you to tailor your post function to your needs using inline scripts. You can add the code inline or upload a script file. If you are comfortable working in Groovy, you may want to use this custom option for your scripted post functions in Jira. If you aren't entirely comfortable, you can still use one of our post function example scripts.
Navigate to ScriptRunner workflow post functions
You can add a ScriptRunner post function to a workflow transition as follows:
Examples of ScriptRunner workflow post functions
Below are some easy-to-follow examples that will help you understand how ScriptRunner workflow post functions work.
Built-in ScriptRunner workflow post functions
Adds a comment to linked issues when this issue is transitioned
Great Adventure needs to add comments on blocked issues when the parent blocker issue has been resolved. This comment should indicate that the main issue was fixed and the blocked issue may be closed now. To help with this situation, Great adventure plans to use the Adds a comment to linked issues when this issue is transitioned post function.
You can now test to see if this post function works:
- Create an issue and a blocked issue that uses the workflow you edited.
- Transition the blocker issue to Done (or equivalent).
- Go to the blocked issue.
- Under Activity, you should see the comment added automatically. If you see the comment added, you are good to go with this script post function.
Assign to first member of role when an issue is high priority
Great Adventure is having problems with high priority bugs being missed by the development team. To resolve this Great Adventure wants to make sure all High and Highest priority issues are automatically assigned to a developer using the Assign to first member of role post function.
You can now test to see if this post function works:
- Create a High or Highest priority issue in your chosen project.
- Check if the new issue is automatically assigned to a developer.
Scripted ScriptRunner workflow post function example
Close all sub-tasks when the parent issue resolution is done
Before you start this example, make sure you have a suitable workflow that includes a transition to Done (or equivalent).
Great Adventure want to close sub-tasks automatically when a parent task is marked as Done. To resolve this Great Adventure can use a Custom script post-function.
This post function is successful if, when the primary task is marked as Done with a Resolution of Done, all associated sub-tasks are also closed.