We are using JIRA Server 7.6.4 and we have Adaptavist ScriptRunner v5.3.9.
I am a developer, but I'm new to script writing in JIRA, and with Groovy.
(Side note - if you have recommendations for tutorials on this topic, I would welcome the pointers.)
I have a custom Date Picker field - Started. When an issue transitions to In Progress I want to
- check if the field already has a value
- if it doesn't, then populate it with today's date
- if it does already have a value, don't change the value
- regardless, still allow the user to edit it before completing the transition.
I think a Behavior is the right way to implement this. I've found multiple examples for prepopulating fields, but haven't been able to get them to work quite right. My stumbling block seems to be figuring out if the field already has a value.
Here is the code I have tried.
if (getActionName() != "In Progress") {
return // not the In Progress transition, so don't set default value}
def cField = getFieldByName("Started")
def cValue = cField.getValue()
if ( cValue ) {
return // Actual Start date set previously. Don't reset}
def newValue = new Date().format("d/MMM/yy")
cField.setFormValue(newValue) With this code, the field is always set to the current date, even if it has a value.
Thanks in advance.