Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scriptrunner code to place in a condition to disallow a transition if currentUser equals a field.

Dave Drexler August 13, 2018

Hi folks - I have a user picker custom field named 'Developer.' I want to disallow the 'Close' transition if currentUser equals the value of 'Developer.'  Seems like it should be pretty straightforward.  

To the Close transition, I added a 'Simple Scripted Condition' and used this:

currentUser != cfValues[13407]

It's not working. (And yes, 13407 is the ID for the 'Developer' field.)

Could someone help me out?

2 answers

1 accepted

0 votes
Answer accepted
Ivan Tovbin
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 13, 2018

Hi Dave,

Here's how you do it:

import com.atlassian.jira.component.ComponentAccessor

def developerCf = ComponentAccessor.getCustomFieldManager().getCustomFieldObject((Long)13407)
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
boolean isValid = true

if(currentUser == issue.getCustomFieldValue(developerCf)){
isValid = false
}
return isValid

Dave Drexler August 13, 2018

Sweet - thank you, Ivan. This worked perfectly.

0 votes
Neta Elyakim
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 14, 2018

Try to use:

currentUser?.name != cfValues["Developer"]?.name

 Or

currentUser?.name != cfValues['customfield_13407'].name
Dave Drexler August 14, 2018

thank you, Neta. If Ivan's approach does not work (still testing that) I'll give your suggestion a whirl. 

I appreciate the help!

Suggest an answer

Log in or Sign up to answer