I need to force a transition when an issue is assigned (via the Assign button), but only if it was previously unassigned. Following the documentation about Fast-track transition an issue,
https://scriptrunner.adaptavist.com/latest/jira/builtin-scripts.html#_fast_track_transition_an_issue
Then building on the example given in the Script Listeners console, I created a listener on the Issue Assigned event, on my project, using this condition:
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
UserMessageUtil.info('Checking condition for fast-track...')
UserMessageUtil.info("i.type=" + issue.issueType.name)
UserMessageUtil.info("issue.new_assignee=" + issue.assignee + ", old.assignee=" + originalIssue.assignee)
// Our issue types + Assignee changed but only if previously was unassigned
def result = (issue.issueType.name in ["FRI Incident", "FRI Service Request"] && (issue.assignee != originalIssue.assignee) && (originalIssue.assignee == null))
UserMessageUtil.info("Result: '" + result + "'")
return result
However, when I open an unassigned issue (which matches the issue type condition) and assign it, the listener is triggered, but the condition always returns false because the value of originlaIssue.assignee apparently is set to the new assignee - see screenshot.
Seems like a bug in the implementation, or a bug in the example.
Anyone?
This condition will return true if previous user was Unassigned and current user is not Unassigned. You can add code to check for issue type as well
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.history.ChangeItemBean
def changeHistoryManager = ComponentAccessor.changeHistoryManager
def assignees = changeHistoryManager.getChangeItemsForField(event.issue, "assignee")
// Sort assignees by date
Collections.sort(assignees, new Comparator<ChangeItemBean>() {
int compare(ChangeItemBean o1, ChangeItemBean o2) {
return o1.getCreated() <=> o2.getCreated()
}
})
def currentUser = assignees[-1].to
def previousUser = assignees[-1].from
currentUser != null && previousUser == null
I've just noticed that the example that I used from the Script Listeners console (Assignee Changed) is tagged as Workflow functions only.
I assume that's the reason why my code does not work as a condition for a stand-alone listener.
I am now using Roland's answer above and it works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.