How to update the status details field (drop down) using python api.

deepak_rohilla September 18, 2022

I have to update the status details field using python script.

Status details is a drop-down field having the below values:

None

Production

Staging. 

I have to set status details field to Staging using python script.

2 answers

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 19, 2022

There's a slight problem with what you're trying to do.  Status is not a field, it is a representation of where an issue is in the workflow for the humans to see.  It mostly looks like a field but it is not.

You can't just edit a status, you have to transition the issue through the workflow.

deepak_rohilla September 20, 2022

I want to update a single select custom field. 

1. issue.update(fields={'customfield_11104': [{'value': 'Staging'}]})

2. issue.update(fields={'customfield_11104': 'Staging'})

both above code show error as "response text = {"errorMessages":[],"errors":{"customfield_11104":"Could not find valid 'id' or 'value' in the Parent Option object."}}"

In that single select field, we have the option Staging still it shows the error. 

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 20, 2022

That suggests your field is a cascading select - you will need to set the parent half of the field as well as the child option.

0 votes
Prince Nyeche
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.
September 18, 2022

Can you show an example of what you're already doing?

deepak_rohilla September 18, 2022

from jira import JIRA
import urllib3
import sys
urllib3.disable_warnings()
API_token = ''
jiraOptions = {'server': 'https://jira.cec.lab.emc.com','verify': False}
authedJira = JIRA(jiraOptions, token_auth=API_token,max_retries=0)
#example
ticket = sys.argv[1]
issue = authedJira.issue(ticket)
issue.fields.labels.append(u'deployment_done')
issue.update(fields={"labels": issue.fields.labels})

 

Using this script i can update labels field.  but I want to update status details.

Prince Nyeche
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.
September 19, 2022

You can perform the same step but the status field is a string and not a list, so you can simply just do

ticket = sys.argv[1]
issue = authedJira.issue(ticket)
issue.fields.status = "Production"
issue.update(fields={"status": issue.fields.status})
deepak_rohilla September 19, 2022

status is a different field I want to update the "status details" field.

I try with your steps for status field but got error:

Traceback (most recent call last):
File "statu_update.py", line 12, in <module>
issue.update(fields={"status": issue.fields.status})
File "/usr/local/lib/python3.8/dist-packages/jira/resources.py", line 715, in update
super().update(async_=async_, jira=jira, notify=notify, fields=data)
File "/usr/local/lib/python3.8/dist-packages/jira/resources.py", line 358, in update
r = self._session.put(self.self + querystring, data=json.dumps(data))
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 593, in put
return self.request('PUT', url, data=data, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/jira/resilientsession.py", line 223, in request
elif raise_on_error(response, **processed_kwargs):
File "/usr/local/lib/python3.8/dist-packages/jira/resilientsession.py", line 69, in raise_on_error
raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 400 url: https://jira.cec.lab.emc.com/rest/api/2/issue/3702014

response headers = {'X-AREQUESTID': '200x1001826x3', 'X-ANODEID': 'jira3n2prd', 'Referrer-Policy': 'strict-origin-when-cross-origin', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Security-Policy': 'sandbox', 'Strict-Transport-Security': 'max-age=31536000', 'Set-Cookie': 'JSESSIONID=jira3n2prd~E85F731D2A10821C07FD337C00158CC8; Path=/; Secure; HttpOnly, atlassian.xsrf.token=B3VN-2ZVW-0G24-EQ32_805930c32b715ccdc407cb50e41b8eb944201570_lin; Path=/; Secure; SameSite=None', 'X-Seraph-LoginReason': 'OK', 'X-ASESSIONID': 'zuyrqz', 'X-AUSERNAME': 'rohild', 'Cache-Control': 'no-cache, no-store, no-transform', 'Content-Encoding': 'gzip', 'Vary': 'User-Agent', 'Content-Type': 'application/json;charset=UTF-8', 'Content-Length': '120', 'Date': 'Mon, 19 Sep 2022 07:20:49 GMT', 'Server': 'Apache'}
response text = {"errorMessages":[],"errors":{"status":"Field 'status' cannot be set. It is not on the appropriate screen, or unknown."}}

Prince Nyeche
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.
September 19, 2022

Well, that's the error message. Add the status field to the screens of your project.

deepak_rohilla September 19, 2022

Status field is already added that is in progress  script still showing the above error. 

But I want to change Status Details field that is: PR Review to Staging.

 

 

Screenshot (69).png

 

Screenshot (70).png

 

In above screen shot Status details (drop down) showing PR review I want to change it to staging.

Prince Nyeche
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.
September 19, 2022

I think we should stick to the name "Status details" just to clarify any naming ambiguity. So this custom field. It is a select choice single field. I think if this field is on screen, you can get the customfield_id and perform the same step as above 

ticket = sys.argv[1]
issue = authedJira.issue(ticket)
issue.update(fields={"customfield_10034": "Production"})

Where customfield_10034 is the customfield id of the "status details" field. You can get this from "/rest/api/2/field" or search your custom field configuration tab from your Jira admin settings.

deepak_rohilla September 19, 2022

issue.update(fields={'customfield_11104': 'Staging'})

i tried this one but got error:

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

 

Status details (customfield_11104) is a drop down field so I tried 

issue.update(fields={'customfield_11104': [{'value': 'Staging'}]})

but got the same error.

 

 

I tried this one also issue.update(fields={'customfield_11104':[{'value':'46707'}]})

got same error.

deepak_rohilla September 19, 2022

Status Details Custom field configuration details. 

"customfield_11104": {"required": false,"schema": {"type": "option","custom": "com.atlassian.jira.plugin.system.customfieldtypes:select","customId": 11104},"name": "Status Details","fieldId": "customfield_11104","hasDefaultValue": false,"operations": ["set"],"allowedValues": 

"value": "Staging","id": "46707","disabled": false}

Prince Nyeche
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.
September 20, 2022

Hey, 

The Jira python library basically fails with the error message as you mention

response text = {"errorMessages":[],"errors":{"customfield_10197":"Specify a valid 'id' or 'name' for Severity Main"}}

Although looking at their documentation, the above should work but somehow it seems to be having an issue even when I tested it. However, you could try another alternative in this article I wrote which uses a different python package.

A minimal representation will be

from jiraone import field, LOGIN

user = "username"
password = "password"
link = "https://yourinstance.yourserver.com"
LOGIN.api = False LOGIN(user=user, password=password, url=link)

values = "Production"
field_name = "Status Details"

field.update_field_data(key_or_id="DSC-404", data=values, find_field=field_name)

You can look into more from the documentation on the field update function. The function allows you to update most Jira fields. 

deepak_rohilla September 21, 2022

issue.update(fields={'customfield_11104': {'value':'Staging'}})

This code working file. Thank you 

Prince Nyeche
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.
September 21, 2022

Good, you got it working.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events