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

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
Answer accepted

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 in Summit

Last chance: registration for Atlassian Open in Vienna ends soon!

Hello, Atlassian Community! The countdown is on for Atlassian Open in Vienna! Read on to discover the top 5 reasons to attend our biggest European event in 2019. At our inaugural Atlassian O...

22 views 0 3
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