To add the 'Build-your-own (scripted)' post-function to a transition:
Click Edit for the workflow that has the transition, you wish to add the post-function on.
In the Workflow Designer, select the transition.
Click on
Post Functions
in the properties panel.Click on
Add post function
.Select
Build-your-own (scripted) post-function
from the list of post-functions.Click on
Add
to add the post-function on the transition.Input an optional description in the “Description” field
Input a Nunjucks template that needs to be executed
Click on "Add post function".
See here for a use case for this post-function
When you add this post-function to a transition and trigger it, the specified arbitrary code gets executed.
Known issues common to all post-functions:
Troubleshooting this post-function configuration: In case the post-function does not work as expected these are the things to look out for
JMWE shows an error message on the issue view if any error occurs during the execution of the post-function. This message is displayed only if the current user is a Jira administrator.
Delayed execution
Post functions are provided with an option to delay their execution. You need to select the number of seconds to wait until the post-function is run, a default of 1 sec to a maximum of 20 seconds.
Workflows that depend on post functions being executed in a specific order fail due to the asynchronous nature of the Connect post-functions in Jira Cloud. One of the workarounds is to delay the execution of the post-functions and thereby create a more predictable execution order. For example, on the approval of a Story you want to create sub-tasks and immediately transition them; in this case, you will have to delay the execution of the Transition Linked Issues post-function, so that the sub-tasks are created before they are transitioned. See the use case below.
It is recommended to use the Sequence of post-functions post-function or Shared Action post-function post-function to run a list of post-functions in a sequence instead of applying a delay.
Sample use cases for Delayed execution
On the creation of a Bug, assign it to a member of the QA team and then add the Assignee to the Watchers.
On the approval of a Story, create subtasks for Development and QA, and transition them to In Progress status.
Use case
Consider a use case where you want to add a worklog entry to the issue. You can do this using the callJira custom Nunjucks filter.
Add the “Build-your-own (scripted)” post-function to the transition
Input the following Nunjucks template
{{ "/rest/api/2/issue/:issue/worklog" | callJira(verb=("post"), params={"issue":issue.key}, body={ "timeSpent": "1w" } ) | dump(2) }}
Save the post-function and publish the workflow
Refer here for more use cases.