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:
- on the history tab of the issue, it shows that I changed Assignee from blank to <a member of the group>
- in the scriptrunner log, first ChangeHistoryItem shows the change to the date field, then 'need to assign', then ChangeHistoryItem again with the detail of the new assignee , then nothing else
- the Assignee field in the ticket appears empty
- in the Issue Navigator list view, the issue appears as Unassigned
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