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 Modifying Checkbox values on transition post-function


I have been looking and experimenting for several days but I cannot find a working solution to change the state of a single customfield checkbox from unchecked to checked or back to unchecked using scriptrunner (Groovy).

I found an almost identical question and I tried modifying the code found here Script runner, how to update custom field that's a select list? 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.fields.config.FieldConfig

def customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
def cf = customFieldManager.getCustomFieldObjectByName("TWU - Combined Tax Review Completed")
def fieldConfig = cf.getRelevantConfig(issue)

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

if (cfValues['Account Type']?.value == 'IRA') {
issue.setCustomFieldValue(cf, value)


Does anyone have some working code that I could work on customizing?


1 answer

1 accepted

1 vote
Answer accepted

That code looks OK, and it should work providing it's the first post-function in the list.

Thanks Jamie, It looks like I am running into a problem with the JIRA installation. I tested the code again and found it works too, but there is some other unrelated issue. Thanks!!!!

Hi @JamieA @Joshua Giffen

I'm trying to do something similar and can't seem to get it to work. It acts like it is working and doesn't through any errors, but it isn't checking the box. 

Any thoughts?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption
import com.atlassian.jira.issue.customfields.manager.OptionsManager


final customFieldName = "Test Type"

//Get custom field issue with this name
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField: "Could not find custom field with name $customFieldName"

def customFieldVal = issue.getCustomFieldValue(customField) as LazyLoadedOption

log.debug "Test Type is ${customFieldVal}"

//set "Add to Regression Set' as field to be updated-
def optionsManager = ComponentAccessor.getComponent(OptionsManager)

//Update "Add to Regression Set" depending on the custom field value
switch (customFieldVal?.value) {
case "Regression Test":
log.debug "Add to Regression Set checkbox should be checked"
def cf = customFieldManager.getCustomFieldObjectByName("Add to Regression Set")
def fieldConfig = cf.getRelevantConfig(issue)
def options = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.value == 'Yes' }
issue.setCustomFieldValue(cf, options)

log.debug "Add to Regression Set value is ${options}"
log.debug "Add to Regression Set checkbox was checked"
log.debug "No need to update the Add to Regression Set checkbox"

Suggest an answer

Log in or Sign up to answer

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