Update a Two Part Custom Field in Jira with Python

Dan-Epiphan February 7, 2018

Hello All,

 

   I am writing a python application to automatically create Jira issues, and am running into an issue with a required custom field that contains two parts.

 

   The custom field is called 'Program' and is identified as 'customfield_14700'.  When you choose the value / option for the Program field (ie. 'Pearl'), there is a second box next to it that is a sub-option (ie. G3 - SW).

 

   When you query the value of the custom field :

        > ticket_obj = jira.issue('MD-7347')
        > print ticket_obj.fields.customfield_14700

   Result :

        > Pearl - G3 - SW

   

   I am using a dictionary to build the create issue request, but am having a problem with the custom field.  So far I have :

 

        issue_dict = {
            'project':{'key':'MD'},
            'summary':'Automated Issue : This is a test',
            'description':'Sample description of the issue.',
            'issuetype':{'name':'Bug'},
            'customfield_14700':{'0':'Pearl', '1':'G3 - SW'}
        }

        new_issue = jira.create_issue(fields=issue_dict)

 

    I know the above customfield_14700 is wrong; it is the closest I can seem to find based on other similar questions.  

 

    I get the following when executing :

 

        response text - {"errorMessages":[],"errors":{"customfield_14700":"Could not find valid 'id' or 'value' in the Parent Option object."}}

 

   I am hoping I am missing something obvious; but am at a loss right now.

 

   Has anyone encountered this scenario / have any thoughts on how to populate values into a two part custom field?

 

   Appreciate any help / suggestions.

 

Thanks!

Dan.

 

 

1 answer

1 accepted

0 votes
Answer accepted
Kyle Moseley
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.
February 8, 2018
'customfield_14700':{'0':'Pearl', '1':'G3 - SW'}

Hope this helps: Cascading Selects return their contents in an array of null and 1, so try null instead of 0

Dan-Epiphan February 9, 2018

Hello Kyle,

   Thank you for your suggestion!  We did notice the 'null' from one of our reports / exports to excel; unfortunately more or less the same response :

 

        issue_dict = {
            ...
            ...
            'customfield_14700':{'null':'Pearl', '1':'G3 - SW'}
        }

 

Response : 

        response text =  {"errorMessages":[],"errors":{"customfield_14700":"Could not find valid 'id' or 'value' in the Parent Option onject."}}

 

   Also tried various spellings (ie. Null, NULL); and tried a None: key as well; same result.  

 

Dan.

Kyle Moseley
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.
February 9, 2018

Try these two:

"customfield_12345" : [{"set" : {"value" : "parentVal", "child": {"value":"childVal"}}}]
"customfield_12345" : {"value" : "parentVal", "child": {"value":"childVal"} } 
Kyle Moseley
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.
February 9, 2018

This is creating issues via the REST api, correct? I assumed this

Dan-Epiphan February 9, 2018

Technically yes, this is being done using the python-jira library for an application we are developing. 

The python-jira library allows us to work with Jira APIs from python.  

Kyle Moseley
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.
February 9, 2018

Okay, just wanted to make sure this wasn't python somehow interacting with the Java API through some sort of magic I haven't seen. Hopefully one of those two solutions above will help.

Dan-Epiphan February 9, 2018

Tried the above suggestions :

For the first one :

        response text = {"errorMessages":[],"errors":{"customfield_14700":"Can not deserialize instance of com.atlassian.jira.issue.fields.rest.json.beans.CustomFieldOptionJsonBean out of START_ARRAY token\n at [Source: N/A; line: -1m column: -1]"}}

 

For the second one :

        We get an error that another custom field is required; however the error for customfield_14700 is no longer present.  I think this has solved the issue; I will resolve the other custom field and let you know shortly.

Thank you!

Dan-Epiphan February 9, 2018

Kyle, thank you very much for your suggestions!  The second option resolved the issue and automation is working well now!

 

Solution is :

 

"customfield_12345" : {"value" : "parentVal", "child": {"value":"childVal"} } 
Ramakrishnan Srinivasan
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 25, 2019

Thank you, it solved my problem as well; this has worked for me 

# https://jira.readthedocs.io/en/master/index.html
from jira import JIRA
import re

options = {
'server': 'https://jirahost.com/jira/',
'verify': False }
jira = JIRA(options, basic_auth=('userid', 'password'))

issue = jira.issue('PROJ-1')

issue.update(fields={'summary' : 'Re-assigned to John Doe' \
,'assignee': {'name':'johnd'} \
, "customfield_14510":{"value" : "Dec-18", "child": {"value":"25%"}} \
, "customfield_14511":{"value" : "Jan-19", "child": {"value":"75%"}} \
})
Tim McCullough
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!
June 4, 2021

This helped me as well!

Suggest an answer

Log in or Sign up to answer