How to use transition in the Scriptrunner Separation of Duties script?

Jason Rittenhouse July 12, 2022

I currently am using Scriptrunner's provided script for separation of duties found here: https://docs.adaptavist.com/sr4js/latest/features/workflows/conditions/built-in-conditions/simple-scripted-condition (script below).

The problem is that this script uses status where I want to use a transition.  I tried changing it from status to transition in the script and while the script didn't give an error, it didn't work either.  My end goal is a workflow condition that will not show the transition to the current user if a specific previous transition was used by that user.  That way the person doing the work can't also approve the work.

The original script is:

import com.atlassian.jira.component.ComponentAccessor

def changeHistoryManager = ComponentAccessor.getChangeHistoryManager()
def currentUserKey = ComponentAccessor.getJiraAuthenticationContext().getUser()?.key

// returns true if there are no transitions to the target state by the current user
!changeHistoryManager.getAllChangeItems(issue).find {
    it.field == "status" &&
        currentUserKey == it.userKey &&
        "Resolved" in it.toValues.values()
}

 

1 answer

1 accepted

0 votes
Answer accepted
Jason Rittenhouse July 18, 2022

The answer, in case anyone else has this use case, is to check for the "from" status as well as the "to" status, like this:


it.field == "status" &&
currentUserKey == it.userKey &&
"In Progress" in it.fromValues.values() &&
"Resolved" in it.toValues.values()
 

In this example, it's checking for any transition from "in progress" to "resolved".

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events