Hi everyone, hope all is well on your end.
With ScriptRunner listener, i am trying to get the Assignee updated whenever the ticket status gets updated. I see that in the History section, the Assignee did get updated, but it is not showing on the top left corner (UI) on the screen.
But when I update a field which i have tied to list of assignees based on the field values, the Assignee did got updated (both in History section and on the UI)
For the event mapping, i have set
1. For issue created, i use ISSUE_CREATED_ID
2. For issue updated, i use ISSUE_UPDATED_ID
3. For status changed, i use ISSUE_GENERICEVENT_ID
Here is my code for updating the assignee:
if(event && event.eventTypeId == ISSUE_GENERICEVENT_ID){
log.debug("Status Updated!!")
Boolean isStatusChanged = isStatusChangedEvent(event, issue)
if(isStatusChanged){
log.debug("isStatusChanged=$isStatusChanged")
updateAssignee(issue)
}
}
Boolean isStatusChangedEvent(IssueEvent event, MutableIssue issue){
def change = event?.getChangeLog()?.getRelated("ChildChangeItem")?.find {it.field == "status"}
if (change){
log.debug("isStatusChangedEvent")
return true
}else{
log.debug("isStatusChangedEventfalse")
return false
}
}
// Only fires when the eventTypeId is Generic Event
def updateAssignee(MutableIssue issue){
String cf_field_object = getFieldObject(issue)
String cf_field_value = issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(cf_field_object))
String issueProject = issue.getProjectObject().key
String issueType = issue.issueType.name
String issueStatusRaw = issue.getStatus().name
String issueStatus = issueStatusRaw.toUpperCase()
String userID = ""
if (listProjects.contains(issueProject)){
if (issueType == "A") {
userID = "assigneeA"
} else if (issueType == "B"){
if (issueStatus == "statusB1"){
userID = "assigneeB1"
} else if (issueStatus == "statusB2"){
userID = "assigneeB2"
} else if (issueStatus == "statusB3"){
userID = "assigneeB3"
} else {
log.debug("Still same assignee")
return
}
}
}
ApplicationUser user = userManager.getUserByName(userID)
String userKey = user?.getName()
issueInputParameters.setAssigneeId(userKey)
}
Any pointers are greatly appreciated!