Hi
I am trying to use a listener to assign an issue randomly from members of a group (in a group picker field) when a date field is set to a date within a week of now.
The random assignment from the group works fine and the date compare works fine.
Here's my code
import com.atlassian.jira.component.ComponentAccessor
def issue = event.issue
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def lastChangedItem = changeHistoryManager.getAllChangeItems(issue).last() as String
def endDate = issue.getCustomFieldValue(11019) as Date
def nowPlus7 = new Date() + 7
def customFieldManager = ComponentAccessor.customFieldManager
def endDateField = customFieldManager.getCustomFieldObject(11019)
def endDateName = endDateField.fieldName
log.warn(lastChangedItem)
if (lastChangedItem.contains(endDateName)){
if (endDate.before(nowPlus7)){
log.warn('need to assign')
def groupManager = ComponentAccessor.getGroupManager()
def group = issue.getCustomFieldValue(19200)
def users = groupManager.getUsersInGroup(group).toSorted{it.key}
users.shuffle()
issue.update { setAssignee(users.first()) }
log.warn(users.first())
log.warn(issue.assignee)
}
}
This is what happens after I edit the date field:
Can anyone advise what is the problem here. Happy to take any other advice on improving the code too, but the main thing I need to understand is this disconnect between the History tab and logs on one hand and the Assignee field on the other.
Thanks,
Julia