Setting field defaults is erasing when user edits issue

Hi,

I am using a behaviour to set a field default based on the selection from a select list field.

When the user creates the issue, the field defaults are set correctly and the issue is created with the defaults in there. However, when the user edits the issue, if they added text to the defaults, anything that they entered is erased and set back to the original default. I know why this is the case, but don't know what condition to put in there to fix it. I have a condition "if (getActionName() != "Create Issue")", so that will pertain to editing an issue as well and will set the defaults again. My code is below, can you please help with a condition to use so that the fields don't get reset.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil

def dep = getFieldByName("Deployment Instructions")

def depVal = dep.getValue().toString()

def app = getFieldByName("Application")

def appVal = app.getValue().toString()

def ODIValue =

"""ODI Repository:
Delete existing scenarios? (yes/no):
Export Key (yes/no):
Subversion path:
Import Schedules? (yes/no):
List the scenarios to be imported below:""".replaceAll(/ /, '')

def WMValue =

"""Deployer Server:
Deployer Project:
Deployment Candidate:""".replaceAll(/ /, '')


def SOAValue =

"""Object Type (SOA, DVM, XSD):
Target Environment (e.g. test-na-1):
Deployment or Composite String:""".replaceAll(/ /, '')

if (getActionName() != "Create Issue"){

if (appVal == "ODI"){
dep.setFormValue(ODIValue)
}

if (appVal == "WebMethods"){
dep.setFormValue(WMValue)
}

if (appVal == "SOA Suite"){
dep.setFormValue(SOAValue)
}

if (appVal != "ODI" & appVal != "SOA Suite" & appVal != "WebMethods"){
dep.setFormValue("")
}
}


Thanks in advance!

Nick

1 answer

0 vote

You can really only use this on Create, where the text won't have a value.

I get in your case you can't do that because it should only use the default if the user selected a particular value from some other field.

So either create a different issue type for this, or you have check whether the field you are writing to is empty. If it might already have some other default you need to check the entire text is unchanged from any of the defaults.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Jul 10, 2018 in Marketplace Apps

If you’re an Atlassian app developer, you’ll want to know about Atlas Camp!

This September 6-7, hundreds of Atlassian App developers will flock to Barcelona Spain to build skills, discover product roadmaps, meet face-to-face with the Atlassian team, and learn how to extend t...

173 views 0 4
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