How to apply Behaviour script globally for create Issue event?

Hi guys,

I have the following script (based on example from https://answers.atlassian.com/questions/38845277).

What I am trying to figure out, is if there is a way to have it fire only during issue create issue events – regardless of workflow. I have several workflows, and I don't want to create individual behaviours for each workflow's create issue transition.

Any tips? Below is the behaviour I have currently:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.Option
def issue = getIssueContext().getIssueTypeObject()
def issueType = issue.getName()
def radioButton = getFieldById(getFieldChanged()) // Radio Button
if (issueType == "Foobar") {
 radioButton.setFormValue(optionFor(radioButton, "Yes").optionId)
} else {
 radioButton.setFormValue(optionFor(radioButton, "No").optionId)
}
private Option optionFor(FormField radioButton, String value) {
 def optionsManager = ComponentAccessor.getOptionsManager()
 def customFieldManager = ComponentAccessor.getCustomFieldManager()
 def customField = customFieldManager.getCustomFieldObject(radioButton.getFieldId())
 def config = customField.getRelevantConfig(getIssueContext())
 def options = optionsManager.getOptions(config)
 def optionToSelect = options.find { it.value == value }
 optionToSelect
}

Thanks for the help!

2 answers

1 accepted

1 votes

I would apply it globally, then you can check if that issue already exists. If it doesn't it must be the "create" action:

import com.onresolve.jira.groovy.user.FieldBehaviours

if (! getUnderlyingIssue()) {
    /// this is create...
}

Thank you Jamie – that worked like a charm!

In case there is any confusion – I don't want it to fire while editing a ticket. Only during ticket creation.

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

2,754 views 11 18
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