How do you set a Jira checkbox field using a JSS Jython post function?

Hi,

I've recently started using JIRA Scripting Suite and have been able to work out how to do everything I've needed to do, other than setting the value of a custom checkbox field in a post function. My checkbox field only has one component, and I'm trying to cause it to be selected for a certain issue type in a post function. My script is shown below - it doesn't produce an error other than to state that "JIRA couldn't create the issue right now". Any help would be much appreciated.

from com.atlassian.jira.component import ComponentAccessor
 
customFieldManager = ComponentAccessor.getCustomFieldManager()
cf_chk1 = customFieldManager.getCustomFieldObjectByName("chk1")
values = [{ "true": "Requires Attention" }]
if issue.getIssueTypeId() == "10000":
   customFieldManager.getCustomFieldType().updateValue(cf_chk1, issue, values)

1 answer

1 accepted

1 vote
Accepted answer

Hi,

I'm not an expert but afaik you need to pass an array of com.atlassian.jira.issue.customfields.option.Option as value.

Something along the lines of:

from com.atlassian.jira.component import ComponentAccessor
  
customFieldManager = ComponentAccessor.getCustomFieldManager()
optionsManager = ComponentAccessor.getOptionsManager()
 
cf_chk1 = customFieldManager.getCustomFieldObjectByName("chk1")
 
# get Option for 'Requires Attention'
fieldConfig = cf_chk1.getRelevantConfig(issue)
options = optionsManager.getOptions(fieldConfig)
requiresAttention = options.getOptionForValue('Requires Attention', None)


if issue.getIssueTypeId() == "10000":
   issue.setCustomFieldValue(cf_chk1, [requiresAttention])

Thank you so much - it worked like a dream first time! You wouldn't believe how many different attempts I've made to set a checkbox field.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published yesterday in Agile

Are you a Jira Service Desk agent? We want to talk to you!

Are you a whiz at handling tickets and looking at how you can further optimize your workflow with automation? Do you tackle detailed customer support questions while simultaneously getting flooded wi...

40 views 0 2
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you