Is it possible to combine conditions and post functions?

Aaron Jones April 30, 2013

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
Answer accepted
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 1, 2013

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!

skorzinetzki May 1, 2013

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.

Volodymyr Chugai April 22, 2016

@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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 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')]
issue.setFixVersions(v)

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

Henning

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2013

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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 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.

Aaron Jones May 1, 2013

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!

1 vote
Ruben Straube February 11, 2014

Hello Aaron,

the new Workflow Enhancer might be for you: https://marketplace.atlassian.com/plugins/com.tng.jira.plugins.workflowenhancerIt'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!

1 vote
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2013

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.

0 votes
Bob Swift OSS (Bob Swift Atlassian Apps)
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 11, 2014

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).

0 votes
Aaron Jones May 1, 2013

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.

0 votes
Udo Brand
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 2013

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.

0 votes
Timothy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 1, 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.

0 votes
Natalie Hobson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 30, 2013

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.

Suggest an answer

Log in or Sign up to answer