Hello everyone,
We want to have a field that shows the (last) user who solved an issue. We define resolving by the transition when resolution field is set.
I tried to use scriprunner Custom Script Field (User Picker - single user).
I didn't find any best practices for scriprunner and tried to make my own scripted field. However, I failed by returning a com.atlassian.jira.user.ApplicationUser. I can get the userkey, but how do I get an ApplicationUser from a given userkey.
Can anyone help me with this?
import com.atlassian.jira.issue.changehistory.ChangeHistoryItem
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def changer = ApplicationUser
def changerKeyString
// Every resolution change is checked
def changeItems = changeHistoryManager.getAllChangeItems(issue)
changeItems.reverse().each { ChangeHistoryItem item ->
if(item.getField() == "resolution" && item.getTos()){
log.warn("resolutino changed")
changer = item.getUserKey()
changerKeyString = item.getUserKey()
log.warn(changerKeyString)
log.warn(item)
}
}
In an test example I get the following:
2023-12-21 15:01:51,004 WARN [runner.ScriptBindingsManager]: resolutino changed
2023-12-21 15:01:51,004 WARN [runner.ScriptBindingsManager]: JIRAUSER152025
2023-12-21 15:01:51,004 WARN [runner.ScriptBindingsManager]: ChangeHistoryItem{id=18724097, changeGroupId=14400601, userKey='JIRAUSER152025', field='resolution', projectId=1234, issueId=123789, issueKey='PLAN-9959', created=2023-10-20 16:14:17.0, nextChangeCreated=292278994-08-17 08:12:55.807, fromValues={}, toValues={10200=Rejected}}