I want to set a custom date field using a post function, but I only want to capture the current date if the field has not yet been set. I'd use a regular post function to do this, but once this field is populated, I don't want it to get overwritten, which is why I've turned to a script for this. I'm very new to groovy scripting and don't have much of a coding background - here's my attempt after looking at a lot of resources here on Answers and elsewhere.
import java.util.*
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.CustomFieldManager
import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
def date = new Date()
Issue issue = issue
def funcDate = issue.getCustomFieldValue( customFieldManager.getCustomFieldObjectByName("Ready for Func Test") )
if (!funcDate) // if this field is empty, then the current date is set for this field
issue.setCustomFieldValue("Ready for Func Test", date)Basically, we want to be able to report on the date in which the issue was first transitioned to a particular status. I don't want to overwrite the value if the same transition is used again (which is very possible in our workflow setup). I've tried several variations of the code above, but I can't seem to get it to work the way I want it to. Even if the field is empty, the field does not get a value set to it during the transition for which I've configured this post function.
Is what I'm trying to do possible via a scripted post function? Am I at least close?
Thanks for your help in advance!