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
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Posted 11 hours ago in Industry Groups

Upcoming Team Tour Government Symposium in Washington D.C.

Calling all Community members from the Washington D.C. area! Atlassian’s Team Tour is heading to your city to host a Government Symposium on May 1st. Join our team and other government agencies to le...

14 views 0 1
View post

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