[JIRA] Behaviours: Restricting an initializer by workflow

I had this problem when I was writing an initializer script for one of the custom fields in my JIRA instance.

This initializer is expected to work on projects of a certain JIRA workflow. It is also expected to work for all workflow actions including “Create”. Because this behaviour is expected to run at issue creation as well, finding the workflow object through ‘underlyingIssue’ object (which is null at the time of issue creation) wasn’t helpful.

Here’s the pseudo-code:

if (currentWorkflow = "My new workflow") {
    // execute the behaviour

Why? Custom field contexts isn’t helpful when working with over hundreds of projects. Every time a project is onboarded to my new workflow, it’s a hassle to configure appropriate custom field context for the project too.

So here’s the workaround I found:

import com.atlassian.jira.component.ComponentAccessor

if (! ( getAction() in ComponentAccessor.workflowManager.getWorkflow("My new workflow").allActions )) return
// if current action doesn't belong to my new workflow, then return and do nothing

I hope if Adaptavist could bundle a ‘getWorkflow()’ function to retrieve workflow information other than action and step details when using initializers.

[JIRA] Behaviours: Restricting an initializer by workflow

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s