Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

adding customfield with drop down values from python api

Jonathan Birchall
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!
January 9, 2024

Are/is there any examples of setting customfield values for a customfield with a tick box setup.

 

I am able to do - 

datadict = {}
datadict['project'] = project
datadict['summary'] = summary
datadict['description'] = description
datadict['issuetype'] = {'name':'Operations Change'}
datadict['duedate'] = date
datadict['labels'] = labelsdatadict['customfield_10263'] = {'value':platform}
datadict['customfield_10262'] = {'value':'Reference Data'}
datadict['customfield_10261'] = how

session.create_issue(fields=datadict)

But I want to add to a customfield with a tickbox and I can see 

Field: customfield_10346 Value: [{'self': 'https://aquis.atlassian.net/rest/api/2/customFieldOption/10544', 'value': 'Prod', 'id': '10544'}, {'self': 'https://aquis.atlassian.net/rest/api/2/customFieldOption/10545', 'value': 'Test', 'id': '10545'}]

so do I need to know the customFieldOption ids for all those options.

would the correct approach to be to build up a list of values for values I need

ids = { 'Prod':'10544,'Test':'10545']  etc 

and the build the list to look something like below? 

datadict['customfield_10346'] =[ {'self': 'https://aquis.atlassian.net/rest/api/2/customFieldOption/10544', 'value': 'Prod', 'id': '10544'}, {'self': 'https://aquis.atlassian.net/rest/api/2/customFieldOption/10545', 'value': 'Test', 'id': '10545'}]

 

Any pointers appreciated.

2 answers

2 accepted

0 votes
Answer accepted
Jonathan Birchall
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!
January 10, 2024

To answer my own question with some imput from David Bakkers

geerate a list of the tickbox items needed -- 

values = [{'value':'Prod'},{'value':'Test'}]

then using the customfield i posted 

datadict['customfield_10346'] = values 

0 votes
Answer accepted
Sunny Ape
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.
January 9, 2024

Hello @Jonathan Birchall 

so do I need to know the customFieldOption ids for all those options.

Only if you are changing an existing option's value. The ID per option is because options are allowed to have identical values, so you need a unique identifier to reference them.

would the correct approach to be to build up a list of values for values I need

Yes, if you are adding a complete set of options to the field. Once you add all the options and their values, each option will automatically be given a unique IDs (IE. you do not declare an ID when creating the options, Jira handles that).

Note. If you want to add new options to an existing set for an existing field, you can't insert or append them, you have to erase and re-build the whole option set for that field:

  1. Get the field's existing options and their values and store them in an array in your code.
  2. Put the new options and their values into the appropriate place in the array set.
  3. Delete all the existing options from the field.
  4. Using the array, put the entire new set of options and their values into the field, in the order you need them to be in.
  5. Jira will generate all new IDs for all those options.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events