Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

scriptrunner listener issue with the post function snippets


I've created a built-in listener "Fast-track transition an issue" with scriptrunner plugin from Adaptavist

The event is fired properly, the transition is executed and some post-functions are also executed.

One of this post function is to update a custom field (a select-list one).

I've copied the "Set select list custom field" snippet" which is :

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Some Select List") // name of CF
def optionsManager = ComponentAccessor.getOptionsManager()
def fieldConfig = customField.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).find { it.value == "Yes" } // value of option

issueInputParameters.addCustomFieldValue(, option.optionId as String)


The code analysis sets a warning on the customFieldManager definition, saying "Variable "customFieldManager" masks a binding variable. Please choose a different name for variable: "customFieldManager" @ line 8, column 5.


I've several listeners configured the same way (but with different custom fields...all select-list). Some works, some don't...

I'm new with scriptrunner so I may have missed something...but I would exect built-in snippets to work from scratch....

If someone from Adaptavist could help, this would be great !

1 answer

Hi @Stéphane Blondeau 
Just to be sure if I understand.
You have a customField that is a select-list. 
And this field have X options and on your code you want to select the option with "yes" value. 
Am I right?

Hi Gustavo.

yes this is exactly the case.

To be precise, I’ve configured several listeners with different field names and options values...but if it works with this value...I’m sure I will make it work with others...


def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Some Select List") 

def fieldConfig = customField.getRelevantConfig(issue)

def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find{it.toString()=='yes'}


This is working for me, I hope it works for you aswell.


Could you give me the complete script (with import declarations) ?

By the way, the problem remains regarding this line :

def customFieldManager = ComponentAccessor.getCustomFieldManager()

I still have the same warning preventing the code to be executed :

Variable "customFieldManager" masks a binding variable. Please choose a different name for variable: "customFieldManager" @ line 8, column 5

Sure, I forgot the imports.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.util.UserUtil
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IssueIndexingService
import com.atlassian.jira.event.type.EventDispatchOption

def issue = issue as MutableIssue
def userManager = ComponentAccessor.getComponent(UserManager)
UserUtil userUtil = ComponentAccessor.getUserUtil()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
IssueManager issueManager = ComponentAccessor.getIssueManager()
def issueIndexingService = ComponentAccessor.getComponent(IssueIndexingService)
def selectField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("select")
def customFieldM = ComponentAccessor.getCustomFieldManager()
def fieldConfig = selectField.getRelevantConfig(issue)
def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find{ it.toString() == 'yes' }

This is my complete script with the variables I used.

Thanks again.

I've simply copied your script in the post-function tab of the listener and I have the same issue with this line :

def issue = issue as MutableIssue

Not sure, but it seems "issue" is already defined when using the built-in listener option (fast track transition).

Do you use this script with a fast track transition listener ? or in an other context ?

I'm using it in a Post Function, when the issue is created.

I think the equivalent in a listener would be 
def issue = event.issue or MutableIssue issue = event.issue as MutableIssue

Well thanks again...

but this doesn't help regarding this error :

Variable "customFieldManager" masks a binding variable. Please choose a different name for variable: "customFieldManager" @ line 8, column 5

I've tried to rename the variable, but some other errors appear...

Sorry, I'm not sure what the error could be without seeing the entire script.
I just noticed that I didnt need that line,
In my script, 
def customFieldM = ComponentAccessor.getCustomFieldManager()
"customFieldM" is not used.
Could you remove it to see if another error appears?

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

72 views 1 6
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you