Use Case: I want to create a custom field that will be updated when a user 'flags' an issue as blocked.
Attempted Solution: I've created a Custom Date Picker (and Date Time Picker) as well as a Listener that looks for updates to the Flagged field. If the issue is flagged, I populate the Picker with the current date/time via a groovy script.
Observations: I was finally able to get the Picker to display on the issue selected screen and it shows the correct values. However, when attempting to query on the Custom Picker field, it shows as EMPTY. If I manually choose the Picker and set a date, the JQL works as expected. e.g. Flagged is not EMPTY and "Flagged Date" is not EMPTY returns nothing unless I set Flagged Date via the GUI.
I did reindex and no change.
Thoughts?
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
//Set up the issue
def issueEventManager = ComponentAccessor.getIssueEventManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issue = event.issue as Issue
//The field to WATCH and its VALUE
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find{it.name == "Flagged"}
def chgField = customFieldManager.getCustomFieldObjects(event.issue).find{it.name == "Flagged"}
def chgFieldValue = chgField.getValue(event.issue).toString()
//The field we want to change
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find{it.name == "Flagged Date"}
def changeHolder = new DefaultIssueChangeHolder()
//Set up the current date
def newDate = java.sql.Timestamp.valueOf("2021-06-07 00:00:00.0")
if(!change)
{
//we're done
}
else
{
change.each
{
if(chgFieldValue=="null")
{
//Flag was cleared - clear out date
tgtField.updateValue(null,issue.new ModifiedValue(issue.getcustomFieldValue(tgtField), null),changeHolder)
}
else
{
//Flag was set - set current date
tgtField.updateValue(null,issue.new ModifiedValue(issue.getcustomFieldValue(tgtField), newDate),changeHolder)
}
}
}
UPDATE: I think the issue must be something in the POST (or whatever it's called in JIRA) of the updates. The automatic date entry via the script above LOOKS fine on the screens and the values appear and are cleared as expected. However, if I try to query on the date field using JQL, the date field comes back as EMPTY. Here's the weird part. If I add a COMMENT or some other update to the issue (via the GUI, not within the script - tried that), then the date field is queryable. I'm not sure what's going on.