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()) {
fixVersion.setFormValue(defaultFixVersion)
}

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
Posted Oct 11, 2018 in Marketplace Apps

You + one app + a desert island...

Hi all! My name is Miles and I work on the Marketplace team. We’re looking for better ways to recommend and suggest apps that are truly crowd favorites, so of course we wanted to poll the Community. ...

2,361 views 5 6
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