Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Tiago Fernandes November 5, 2017

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

1 vote
Jonny Carter
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.
November 19, 2017

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)
}
Tiago Fernandes November 21, 2017

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.

Jonny Carter
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.
November 22, 2017

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.

Like Petr Papousek likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events