Hi,
I am using below groovy script to update a custom field of type DateTime Picker every time another field is changed. Update goes fine and I can see that the value of the customfield has been updated. But when I perform a jql search, like say "AutomationUpdatedOn > startOfDay()", it doesn't show me these updated fields unless I update the same field twice. I have tried many things like re-indexing, reIndex(issue) inside my code, but not help.
class UpdateField extends AbstractIssueEventListener {
Logger log = Logger.getLogger(UpdateField.class)
@Override
void workflowEvent(IssueEvent event) {
log.setLevel(org.apache.log4j.Level.DEBUG)
def field = event.getChangeLog().getRelated('ChildChangeItem').any{
it.field.toString().equals("Test Automation")
}
if(field){
MutableIssue issue = event.issue
ComponentManager componentManager = ComponentManager.getInstance()
IssueIndexManager indexManager = ComponentManager.getIndexManager();
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager();
def issueManager = componentManager.getIssueManager()
CustomField automationUpdated = customFieldManager.getCustomFieldObjectByName( "AutomationUpdatedOn" );
issue.setCustomFieldValue(automationUpdated,new Timestamp(new Date().getTime()))
User currentUserObj = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
issueManager.updateIssue(currentUserObj, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
issue.store()
}
}
}