Forums

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

How to update a custom field dropdown/search menu using jira python api?

Yang, Nini August 28, 2024

Hi, I was wondering if someone could help explain how I would be able to update a custom field using the jira python api.

Normally, this custom field is added manually by typing the item key to be attached into the search bar, then selecting the item that appears from the drop-down menu. Once selected, the item appears as a box under the custom field. After saving, the same linked item can be viewed after closing and re-opening the edit menu. 

 

I attempted to update the custom field using 

new_issue.update(fields = {"[custom field id]": { "key": feature_issue.key }})

but the field doesn't seem to link the given key to an actual item as the selection disappears upon re-opening the edit menu

 

Hopefully my drawings below can explain my ask. Any guidance is appreciated, thanks!

 

ask.png

 

 

 

 

 

 

 

1 answer

1 accepted

0 votes
Answer accepted
Trudy Claspill
Community Champion
August 28, 2024

Hello @Yang, Nini 

Welcome to the Atlassian community.

What is the field type of the custom field? Is the custom field a multi-select Issue Picker field?

For a multiple selection list I believe you need to declare each value you want to add as a pair inside of curly braces and use "value" as the key.

{"value": feature_issue.key}

And since you might have multiple values you would separate them with commas:

{"value": feature_issue.key}, {"value": another_issue.key}

And encompass the entire list in square brackets

[{"value": feature_issue.key}, {"value": another_issue.key}]

If you have only one value to add you still need to encompass it in brackets.

[{"value": feature_issue.key}]

 

So, try this:

new_issue.update(fields = {"[custom field id]": [{ "value": feature_issue.key }]})

Yang, Nini September 12, 2024

Hi Trudy, thanks for the warm regards and response! The custom field type is a multi-select issue field. I tried your suggestion but received the following error:

 

raise TypeError(f'Object of type {o.class.name} '
TypeError: Object of type Issue is not JSON serializable

 

 

Trudy Claspill
Community Champion
September 12, 2024

Can you share your updated code, please?

Yang, Nini September 24, 2024

Hi Trudy,

 

Here is the updated section of code that performs the jira functions. Names of certain items were changed but functions are unchanged


main_issue = issue key read from an excel sheet
       
fields["summary"] = "[summary] " + main_issue.fields.summary             # set issue summary to be: "[summary] {Feature Summary}""
fields["customfield_A"] = main_issue.fields.customfield_A        # set customfield A to be same as main_issue
fields["customfield_B"] = main_issue.fields.customfield_B        # set customfield B to be same as main_issue

new_issue = jira.create_issue(fields = fields)                              # create new issue

new_issue.update(priority = {"id": main_issue.fields.priority.id})       # update priority of new_issue
new_issue.update(fields = {"customfield_C":  [{main_issue.key }]})     # update multi select custom field to link to the main_issue

Suggest an answer

Log in or Sign up to answer