Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

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

Harvey Shepherd
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 9, 2016

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Rp Subhub
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2016

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])
Harvey Shepherd
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 12, 2016

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.

TAGS
AUG Leaders

Atlassian Community Events