Hi,
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?
Thanks
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!!!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
log.setLevel(org.apache.log4j.Level.DEBUG)
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"
break
default:
log.debug "No need to update the Add to Regression Set checkbox"
break
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Join us to learn how your team can stay fully engaged in meetings without worrying about writing everything down. Dive into Loom's newest feature, Loom AI for meetings, which automatically takes notes and tracks action items.
Register today!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.