1

I'm trying to use the JIRA Python API to create and update issues on different projects.

Currently I'm after timetracking but I've seen other fields that cannot be set on this or that project getting the error message:

... cannot be set. It is not on the appropriate screen, or unknown.

I can already set timetracking on some projects like:

issue.update(fields={'timetracking': {'originalEstimate': '4h'}})

But on others I get the mentioned error message although the field is clearly present among the issue fields:

>>> issue.fields.timetracking
<JIRA TimeTracking at 2072336111640>

There seems to be nothing obvious on the object itself that could make me identify the thing as "not set-able".

Here is a post on how to get the fields on the screen via REST API. I think that's what the Python thing is doing in the background. But do I really need to go that way?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
ewerybody
  • 1,443
  • 16
  • 29

1 Answers1

0

Given the path from the REST API question answer we can get the data with the private _get_json:

path = 'issue/createmeta?projectKeys={KEY}&expand=projects.issuetypes.fields'

data = jira_connection._get_json(_FIELDS_PATH.format(KEY=project_key))

project_fields = {}
for issuetype in data['projects'][0]['issuetypes']:
    project_fields[issuetype['name']] = dict((f, v['name']) for f,v in issuetype['fields'].items())

This will result in a project_fields dictionary like:

{
    "ISSUE_TYPE_NAME": {
        "FIELD_ID": "FIELD_NAME",
        ...
    }, // for example:
    "Task": {
        "summary": "Summary",
        "issuetype": "Issue Type",
        ...
    }
}

As long as there is no such feature in the jira package directly.

ewerybody
  • 1,443
  • 16
  • 29
  • Important to note: Fields are different per project per issue type! "Task" can have different fields than "Bug" of course but "Task" can also have different fields on project X or Y! – ewerybody Apr 27 '22 at 10:01