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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

348 views 0 6
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