Preventing ScriptRunner's Behaviour from overwritting fields filled by "create another" option

I'm using Script Runner's Behaviours to have a default value for fixversion when creating a ticket. In this scenario, how could I prevent Behaviours from setting that field's value when the user chooses the option "create another" to create one more ticket?

1 answer

The Create Another checkbox copies over fields all on its own to start with. Behaviours are javascript-based, meaning that they start after the form is loaded. As such, you should be able to tell your behaviour to only add the default value if the field is empty. You'll still get the copied value from the previous issue (which is what you want, I reckon).

Something like:

import com.atlassian.jira.issue.IssueFieldConstants

def fixVersion = getFieldById(IssueFieldConstants.FIX_FOR_VERSIONS)
def defaultFixVersion //set your default fix version here
if (!fixVersion.getValue()) {

Unfortunately that doesn't seem to work. When I check the value of fixVersion, it always returns null. Same thing for other fields that are pre-filled by the "create another" functionality.

I can successfully set the value of fixVersion, but it always overwrites the value that "create another" would have put in there.

Hm, you're right. Having reproduced this, it doesn't even look like Behaviours is firing before the "Create another" functionality populates that field. The version is there from the previous issue, then it gets overwritten.

However, if I put the same script on the Fix Version/s field instead of in an initializer, it seems to work as you'd want.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,687 views 3 11
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