Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to get the below columns for all the issues in an excel sheet using Jira python

I want the key, Summary, Assignee Name, Worklog(timeSpent), Epic to which it is related, Story it is related to, and the issue type.

Ps: issues.fields.timeSpent shows the error: AttributeError: type object 'PropertyHolder' has no attribute 'timeSpent'.

1 answer

0 votes
Prince Nyeche Community Leader Oct 30, 2020

Hi @Mayank jain 

Please elaborate in details what the issue is and what you've tried in future for clarity?

example "I am using this code in python to extract this <data>, I tried the below <code> and I got the below <error>, what went wrong" That way we could actually troubleshoot what went wrong.

from your question I don't know where to start from rather than ask you another question which is "can you show the exact code being used"?

I am using the below code for for first 4 details:

import jira.client
from jira.client import JIRA
from openpyxl import Workbook

jira_options={'server': 'server_name'}
jira=JIRA(options=jira_options,basic_auth=('username','pass'))


key_list = []
summary_list = []
description_list=[]
assignee_list=[]
worklog_list=[]

#Add additional lists for fields here
#Example:
#description_list = []
def get_all_issues(jira_client, project_name, fields):
issues = []
i = 0
chunk_size = 100
while True:
chunk = jira.search_issues(f'project = {project_name}', startAt=i, maxResults=chunk_size, fields=fields)
i += chunk_size
issues += chunk.iterable
if i >= chunk.total:
break
return issues
issues_in_project = get_all_issues(jira, '\"Proj Name\"', ["id", "summary", "assignee", "timetracking"])

for issue in issues_in_project:
key_list.append(issue.key)
summary_list.append(issue.fields.summary)
assignee_list.append(str(issue.fields.assignee))
worklog_list.append(issue.fields.timetracking.timeSpent)

 

wb = Workbook()
ws = wb.active
key_row = 1
summary_row = 1
description_row=1
assignee_row=1
worklog_row=1

start_column = 1

 

for key in key_list:
ws.cell(row=key_row, column=start_column).value = key
key_row += 1

for summary in summary_list:
ws.cell(row=summary_row, column=start_column+1).value = summary
summary_row += 1
for assignee in assignee_list:
ws.cell(row=assignee_row, column=start_column).value = assignee
assignee_row += 1
for worklog in worklog_list:
ws.cell(row=worklog_row, column=start_column).value = worklog
worklog_row += 1

wb.save("jira-report.xlsx")

TypeError: 'TimeTracking' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\Users\kaka\Desktop\Jira_Automation\tds.py", line 35, in <module>
worklog_list.append(issue.fields.timetracking.timeSpent)
File "C:\Users\jaja\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\jira\resources.py", line 161, in __getattr__
return self[item]
TypeError: 'TimeTracking' object is not subscriptable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "c:\Users\tata\Desktop\Jira_Automation\tds.py", line 35, in <module>
worklog_list.append(issue.fields.timetracking.timeSpent)
File "C:\Users\nana\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\jira\resources.py", line 174, in __getattr__
if hasattr(self, 'raw') and item in self.raw:
TypeError: argument of type 'NoneType' is not iterable

print((issue.fields.timetracking.timeSpent))

when I try this for a single issue, it correctly shows the timeSpent on the issue 

Hi,

it looks a little bit like that the error occurs for issues where no time has been logged against. Maybe you should try with something like.

if issue.fields.timetracking.timeSpent:
worklog_list.append(issue.fields.timetracking.timeSpent)

 BR

Hi @Mayank jain 

Thanks for the code and sorry for getting back so late, only had the time today to actually check this out. So the reason behind the error

TypeError: 'TimeTracking' object is not subscriptable

TypeError: argument of type 'NoneType' is not iterable

is because the timetracking field is not visible on screen on Jira having a value of None. you will need to make sure that the field "Time Tracking" is actually visible on screen on Jira issue view and for this to happen the field must have a value e.g 0m for original estimate because the script can't append a none existent value for timespent field. lastly I formatted your code below for clarity.

from jira.client import JIRA
from openpyxl import Workbook

jira_options = {'server': 'server_name'}
jira = JIRA(options=jira_options, basic_auth=('username', 'password'))

key_list = []
summary_list = []
description_list = []
assignee_list = []
worklog_list = []


# Add additional lists for fields here
# Example:
# description_list = []
def get_all_issues(jira_client, project_name, fields):
issues = []
i = 0
chunk_size = 100
while True:
chunk = jira.search_issues(f'project = {project_name}', startAt=i,
maxResults=chunk_size, fields=fields)
i += chunk_size
issues += chunk.iterable
if i >= chunk.total:
break
return issues


issues_in_project = get_all_issues(jira, '\"Project Name\"', ["id", "summary", "assignee", "timetracking"])
for issue in issues_in_project:
key_list.append(issue.key)
summary_list.append(issue.fields.summary)
assignee_list.append(str(issue.fields.assignee))
worklog_list.append(issue.fields.timetracking.timeSpent)


wb = Workbook()
ws = wb.active
key_row = 1
summary_row = 1
description_row = 1
assignee_row = 1
worklog_row = 1

start_column = 1

for key in key_list:
ws.cell(row=key_row, column=start_column).value = key
key_row += 1

for summary in summary_list:
ws.cell(row=summary_row, column=start_column + 1).value = summary
summary_row += 1

for assignee in assignee_list:
ws.cell(row=assignee_row, column=start_column).value = assignee
assignee_row += 1

for worklog in worklog_list:
ws.cell(row=worklog_row, column=start_column).value = worklog
worklog_row += 1

wb.save("jira-report.xlsx")

 

Hope this gives you an idea on how to go about this issue.

Hi @Prince Nyeche ,

Thanks for your reply.

So we don't have work estimates entered for every issue on Jira but we do have the logged hours for all of them.

Is there a way around this(to get the spent time for issues with no estimated hours)?

Prince Nyeche Community Leader Nov 04, 2020

Hi @Mayank jain 

I'm not certain of that yet for a workaround. If you can get it by doing just one, is it the same piece of code being used?

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you