I am trying to retreive worklog entries from Jira Service Management Cloud in python by using the jira-python library.
Everything works fine, except getting the comment from each worklog. The documentation is quite vague on this.
My code currently looks like this:
jira = JIRA(server, basic_auth=(email,token))
<span># define date filter</span>
startDate = datetime.date(<span>2024</span>, <span>2</span>, <span>1</span>)
endDate = datetime.date(<span>2024</span>, <span>2</span>, <span>27</span>)
<span>#define jql to filter issues</span>
jql = <span>"project in (XY) AND issuetype in ('[System] Incident', '[System] Service request') AND status = Closed AND resolutiondate >= {} AND resolutiondate <= {}"</span>.<span>format</span>(startDate, endDate)
<span>#incremental fetch of issues and storage into issues_all</span>
pos = <span>0</span>;
batch = <span>100</span>;
issues_all = []
<span>while</span> <span>True</span>:
issues_batch = jira.search_issues(jql_str=jql, startAt=pos, maxResults=batch, fields=[<span>'worklog'</span>,<span>'customfield_10202'</span>,<span>'customfield_10198'</span>,<span>'customfield_10191'</span>])
<span>if</span> issues_batch == []:
<span>break</span>
<span>else</span>:
issues_all += issues_batch
pos += batch
<span>with</span> <span>open</span>(<span>'jiraExport.csv'</span>, <span>'w'</span>, newline=<span>''</span>, encoding=<span>'utf-8'</span>) <span>as</span> file:
writer = csv.writer(file, delimiter=<span>";"</span>)
fields = [<span>"Issue"</span>, <span>"Issue ID"</span>,<span>"Warranty Basis"</span>,<span>"Warranty"</span>,<span>"Warranty Reason"</span>,<span>"Worklog ID"</span>, <span>"Author Name"</span>, <span>"Author Email"</span>,<span>"Date"</span>, <span>"Time Spent"</span>, <span>"Description"</span>]
writer.writerow(fields)
<span>for</span> issue <span>in</span> issues_all:
current_issue = jira.issue(issue)
worklogs = current_issue.fields.worklog.worklogs
<span>for</span> worklog <span>in</span> worklogs:
worklog_fields = []
worklog_fields.append(current_issue.key)
worklog_fields.append(worklog.issueId)
worklog_fields.append(current_issue.fields.customfield_10202)
worklog_fields.append(current_issue.fields.customfield_10198)
worklog_fields.append(current_issue.fields.customfield_10191)
worklog_fields.append(worklog.<span>id</span>)
worklog_fields.append(worklog.author.displayName)
worklog_fields.append(worklog.author.emailAddress)
worklog_fields.append(functions.datetime_to_date(worklog.started))
worklog_fields.append(functions.seconds_to_industryHours(worklog.timeSpentSeconds))
worklog_fields.append(worklog.comment) <-----
writer.writerow(worklog_fields)
I found some stuff which referenced worklog.comment should work, but I always get the following error, when running my code:
Traceback (most recent call last):
File <span>"C:\Users\xy\AppData\Local\Programs\Python\Python312\Lib\site-packages\jira\resources.py"</span>, line <span>193</span>, <span>in</span> __getattr__
<span>return</span> self[item] <span># type: ignore</span>
~~~~^^^^^^
TypeError: <span>'Worklog'</span> <span>object</span> <span>is</span> <span>not</span> subscriptable
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File <span>"d:\Development\Projects\Jira Interface\main.py"</span>, line <span>58</span>, <span>in</span> <module>
worklog_fields.append(worklog.comment)
^^^^^^^^^^^^^^^
File <span>"C:\Users\xy\AppData\Local\Programs\Python\Python312\Lib\site-packages\jira\resources.py"</span>, line <span>198</span>, <span>in</span> __getattr__
<span>raise</span> AttributeError(
AttributeError: <<span>class</span> <span>'jira.resources.Worklog'</span>> <span>object</span> has no attribute <span>'comment'</span> (<span>'Worklog'</span> <span>object</span> <span>is</span> <span>not</span> subscriptable)Any ideas how to get the comment of each worklog?