Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi,
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(customField.id, option.optionId as String)
issueInputParameters.setSkipScreenCheck(true)
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 !
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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'}
issue.setCustomFieldValue(customField,value)
issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,false)
This is working for me, I hope it works for you aswell.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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' }
issue.setCustomFieldValue(selectField,value)
issueManager.updateIssue(user,issue,EventDispatchOption.DO_NOT_DISPATCH,false)
This is my complete script with the variables I used.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.