Copy Value From Field to Field Function Groovy Condition

I'm using the Copy Value From Field to Field Function Post-Function, but am struggling to figure out the condition portion. Basically, I don't want it to execute the post-function unless a custom field "Reorder Type" contains the string value of "Replace Empty".


What would the Groovy expression be?

1 answer

1 accepted

Many of the conditions for post functions have some handy-dandy variables injected into the binding. I don't see a post function with the name you used, but it might be as simple as:

cfValues['Reorder Type']?.value == 'Replace Empty'

If the Condition blank has a little question mark next to it, click that to see what's available in the binding.

 

In a more general case (outside Post Functions and such like), you could use the CustomFieldMananger to determine the value of the field. Something like

import com.atlassian.jira.component.ComponentAccessor

def customFieldMananger = ComponentAccessor.getCustomFieldManager()
def field = customFieldMananger.getCustomFieldObjectByName("Reorder Type")
def reorderTypeValue = issue.getCustomFieldValue(field)
reorderTypeValue == "Replace Empty"

Notably, that assumes the the Reorder Type field is a simple plain text input. For select lists and other more complex input types, you may need to bust out the OptionsManager as well. See https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/select-list-other.html for an example of using the optionsManager to get and set values in a select list.

This is what is displayed under the condition input field.

 

Type a Groovy expression that returns true if the post-function should run. 
You can use the following variables in your Groovy script:

  • issue: a simple wrapper around the Issue object. Use issue.get("<fieldname>") to get the value of a field
  • issueObject: the Issue object itself
  • log: a Logger instance that writes into atlassian-jira.log (useful for debugging)

Got it. In that case, you'll want to go the more general route and use the ComponentAccessor and CustomFieldMananger classes to interact with the data. Instead of the issue.getCustomFieldValue() method that I used, you might could just use issue.get("Reorder Type"), assuming that covers custom fields. I suspect this is just an older version of ScriptRunner with some slightly different conveniences.

Thanks for the help! That worked!

issue.get("Reorder Type") == "Replace Empty"

This workflow function is actually from the JMWE plugin.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,327 views 14 20
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot