Is it possible to combine conditions and post functions?

What I'm looking to do is execute a post function if a condition is met. The real world example here is that I want to copy a value from a Single Version Picker select list to the "Fix Version(s)" field IF the resolution is "Fixed".

Google's not helping me find a good answer for this and the idea of having a transition for "Fix" and a transition for "Other resolutions" seems convoluted and unnecessary.

9 answers

1 accepted

4 votes
Accepted answer

Natalie and Timothy have mostly covered what I wanted to say on this one.

It boils down to what you really want is

1) to forget "conditions" - that's a word used in Jira for something specific, which is not what you need.

2) Put the logic for deciding what to write, and when, into a post-function. That's what they're for!

This is the way to go!

Use script post function to achieve your goal. If you need help with this, you probably will get it right here on atlassian answers as well.

@Nic Brough [Adaptavist], pls, share example og postfunction:

If status moves to done and issue type bug is bug, then set resolution - fixed, version - earliest one.

3 votes
Henning Tietgens Community Champion May 01, 2013

You can use Script Runner as you already commented and set the fix version within the scripted post function. First you have to find the version you need using the VersionManager before setting it.

VersionManager versionManager = ComponentAccessor.getVersionManager()
def v = [versionManager.getVersion(issue.getProjectObject().id, '1.5')]

'1.5' is the name of the Version you want to set.


Henning beat me to it by 13s... the only thing maybe worth adding to this is to put this function as the first.

Henning Tietgens Community Champion May 01, 2013

Be aware that this replaces all fix versions of the issue! If you want to add the version you have to combine the existing versions (issue.getFixVersions()) with the new one.

This is good. I'll need to make the version a variable to use the value in the custom field, but that's a perfect start.

THanks Henning!

I think it would be a useful feature for post-functions to have "conditions", notwithstanding the terminology clash. That's why I added them to the built-in scripts. Although you can use proper conditions and lots of workflow actions, that's very hard to maintain.

> Beyond that, any help in how to use issue.setFixVersions() to pull the custom field value would be great appreciated

Not really sure what you're trying to do - might be better to ask a new question.

issue.setFixVersions() should work fine if your post-function is *first* in the list - but make sure you pass a Collection of Version objects.

I don't think what you want is a condition - a condition prevents a transition from being selectable if it's not met; but a validator wouldn't do it either - that only prevents a transition from being completed if it's not met. It sounds like what you want is just one post function; that checks to see if the resolution is "Fixed", and if so then set the Fix Version as you say.

Not sure why you don't want to do two transitions, because that seems the natural choice to me - you would have a "Fixed" transition (with a post function that sets the resolution to Fixed and the Fix version to what you want), and another one for the user to manually select the resolution they want.

0 votes
Timothy Chin Community Champion May 01, 2013

Since you said you've already searched, then you're out of luck. You may need to write your own post function for this.

I agree with Natalie. What you need is two transitions, one where your condition is met (resolution is not empty) and one where it's not (resolution is empty). Than add your postfunction to the transition with your condition - and you get what you want.

I get that using a different transition and conditions is the better answer (as opposed to writing my own post function). The only reason for not doing this is that we're in the process of migrating a great many issues from a legacy system that heavily relies on the workflow always being the same. Until that project is complete, I have to come up with another solution.

Using a simple conditional, I can test the resolution with Groovy Runner.

issue.resolution?.name == "Fixed"

Beyond that, any help in how to use issue.setFixVersions() to pull the custom field value would be great appreciated.

Hello Aaron,

the new Workflow Enhancer might be for you:'s free and you can select any post function to be executed depending on a Boolean expression.

We'll greatly value any feedback if this is what you are looking for!

Both Conditioned Workflow Functions for JIRA and Create on Transition Plugin for JIRA provide options for conditioning logic within the post function to determine whether or not to run the requested action. Obviously, these are specific to the actions supported by the plugins (updating issues, creating issues).

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,919 views 19 22
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you