Setting field defaults is erasing when user edits issue

Nick Abdoo December 15, 2016

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 votes
JamieA
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.
December 18, 2016

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
TAGS
AUG Leaders

Atlassian Community Events