0

I would like to history of custom field values.

Below code could give me raw data of the current field value:

from jira import JIRA

jira_options = {'server': 'url'}
jira = JIRA(basic_auth=('user_name', 'password'), options = {'server': 'url'})
issue = jira.issue('id', expand='changelog')
customfield_name = issue.fields.customfield_10000

But, I would like to get previous values too.

Question posted on atlassian explains ChangeHistoryManager would help to achieve this task. How can the same be done on Python?

Karthick Raju
  • 757
  • 8
  • 29

1 Answers1

0

You are on the right track. You have to get the changelog entries of the jira issue and then get the entries in that changelog list (property is called histories) for the values that concern your customfield. Find out what your customfield is named in the changelog item's field property and then filter out only those history item that concern your customfield.

for entry in range(issue.changelog.startAt, issue.changelog.total):
    # do your stuff, for example:
    history_item = issue.changelog.histories[entry]

    timestamp = history_item.created # get the created timestamp of the current changelog entry
    author = history_item.author.displayName # get the person who did the change

    print(f"The user {author} changed the following fields on {timestamp}:")

    changed_items = history_item.items
    for item in changed_items:
        # depending on the field type, it might make more sense to
        # use `item.from` and `item.to` instead of the fromString/toString properties            
        print(f"Field: {item.field} from {item.fromString} to {item.toString}")

You can also use this for-loop at the beginning instead:

for entry in issue.changelog.histories:
    # do your stuff
Christopher Graf
  • 1,929
  • 1
  • 17
  • 34