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.
Kindly run the following script and have a look in the logs what is the value of the Started field when the field is empty:
if (getActionName() != "In Progress") { return // not the In Progress transition, so don't set default value} def cField = getFieldByName("Started") def cValue = cField.getValue() log.error("cValue: " + cValue) if ( cValue ) { return // Actual Start date set previously. Don't reset} def newValue = new Date().format("d/MMM/yy") cField.setFormValue(newValue)
Thank you for the suggestion, Alexey.
Where will the log.error message be written?
Note I am working with an inline script in JIRA, not with an IDE.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Errors will be in the atlassian-jira.log. You can find more info here:
https://confluence.atlassian.com/jira063/where-are-the-application-server-logs-683542381.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the log this message is getting written:
cValue: null
The same message is written when the field is empty and when it is already populated with data.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess, you script works on the initialization of your behaviour. Add the Date Picker field - Started to the behaviour and add this script to the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Alexey,
Based on your comment I finally realized my misunderstanding about the Behavior functionality, and the difference between having a Field Validator script vs. an Initialiser function script.
I moved the script to be a field validator script and it worked as intended.
Thank you for your help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.