Hi Guys,
I want to get details logged by user on daily basis and details should be of last nine weeks.
Could you please suggest and check my code that I am going in right direction or not.
example :-
Key worklogtime logged_date logged_by
203 2h 2018-04-08 xyz
203 1h 2018-04-07 abc
201 4h 2018-04-07 blaah
Piece of Code:-
import jira.client
from jira.client import JIRA
options = {'server': 'https:/example.com', 'verify':False}
jira = JIRA(options, basic_auth=('user', 'password))
issues_in_project = jira.search_issues('project=11372 and Assignee in(xyz,abc)',maxResults=1000)
for value in issues_in_project:
try:
worklogs = jira.worklogs(value.key)
print worklogs.timespent,worklogs.update, worklogs.updateAuthor, worklogs.updated
except:
print("no worklogs")
Got this error :-
Traceback (most recent call last):
File "jira_test_Time_log.py", line 88, in <module>
print worklogs.timespent,worklogs.author,worklogs.updated
AttributeError: 'list' object has no attribute 'timespent'
Exception Exception: Exception('Exception caught in workbook destructor. Explicit close() may be required for workbook.',) in <bound method Workbook.__del__ of <xlsxwriter.workbook.Workbook object at 0x2bbafd0>> ignored
Hi
I think I've spotted what may be the problem, although I'm not familiar with the language you're using, but try this
for value in issues_in_project:
for i in value.fields.worklog.worklogs:
print i.timeSpentSeconds
The second for has changed - you need to tell the second loop where to get the values
Hi Himanshu,
I'm able to return the worklog data related to search results using the following code.
NOTE: The fields="worklog" option needs to be included in the issues_in_project definition for the code to work.
issues_in_project = jira.search_issues('project=11372 and Assignee in(xyz,abc)',maxResults=1000,fields="worklog")
for value in issues_in_project:
try:
print value.fields.worklog.worklogs[0].timeSpent, value.fields.worklog.worklogs[0].update, value.fields.worklog.worklogs[0].updateAuthor
except:
print "Issue has no worklogs"
If you need to retrieve all the worklogs for a given issue you can loop over the index:
for value in issues_in_project:
log_entry_count = len(value.fields.worklog.worklogs)
for i in range(log_entry_count):
print value.key, value.fields.worklog.worklogs[i].timeSpent, value.fields.worklog.worklogs[i].updated, value.fields.worklog.worklogs[i].updateAuthor
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Shaun S @Warren I want to do something like below piece of code :- want to iterate for number of worklogs entries for particular value.key
Code:-
i = 0
for value in issues_in_project:
for i in value:
print value.fields.worklog.worklogs[i].timeSpent, value.fields.worklog.worklogs[i].updated,value.fields.worklog.worklogs[i].updateAuthor,value.key
i = i + 1
Got error :-
Traceback (most recent call last):
File "jira_test_Time_log.py", line 89, in <module>
for i in value:
TypeError: 'Issue' object is not iterable
But I was able to get results from below for 2 indexes:-
for value in issues_in_project:
print value.fields.worklog.worklogs[0].timeSpent, value.fields.worklog.worklogs[0].updated,value.fields.worklog.worklogs[0].updateAuthor,value.key
print value.fields.worklog.worklogs[1].timeSpent, value.fields.worklog.worklogs[1].updated,value.fields.worklog.worklogs[1].updateAuthor,value.key
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want to do something like below piece of code :- want to iterate for number of worklogs entries for particular value.key
Code:-
i = 0
for value in issues_in_project:
for i in value:
print value.fields.worklog.worklogs[i].timeSpent, value.fields.worklog.worklogs[i].updated,value.fields.worklog.worklogs[i].updateAuthor,value.key
i = i + 1
Got error :-
Traceback (most recent call last):
File "jira_test_Time_log.py", line 89, in <module>
for i in value:
TypeError: 'Issue' object is not iterable
But I was able to get results from below for 2 indexes:-
for value in issues_in_project:
print value.fields.worklog.worklogs[0].timeSpent, value.fields.worklog.worklogs[0].updated,value.fields.worklog.worklogs[0].updateAuthor,value.key
print value.fields.worklog.worklogs[1].timeSpent, value.fields.worklog.worklogs[1].updated,value.fields.worklog.worklogs[1].updateAuthor,value.key
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Himanshu_Pant Sorry that you seemed to be unable to post to this thread. However it appears our system flagged your messages as spam for some reason. Once this happens, all the subsequent messages you attempted to post were then also flagged as spam. I have restored these messages, and in turn removed the duplicates as best I could as a moderator. This means we had to remove a number of duplicate posts from this thread.
Sorry this happened, but it is still a manual process to unflag such posts and then manage them.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
I think that you need to use timeSpentSeconds rather than timespent (please note case sensitivity as well) because all Jira time is held in seconds. You can then convert to hours as required.
Hope this helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Shaun S@Warren :- Please have a look below and please suggest.
I am using this :-
for value in issues_in_project:
worklogs = jira.worklogs(value.key)
print worklogs.author
getting error as :-
Traceback (most recent call last):
File "jira_test_Time_log.py", line 89, in <module>
print worklogs.author
AttributeError: 'list' object has no attribute 'author'
I am not getting any output for any object lke author,timespent and timeSpentSeconds
But when I changed my Code :-
for value in issues_in_project:
worklogs = jira.worklogs(value.key)
print worklogs
It is giving the results like :-
[<JIRA Worklog: id=u'372113'>]
[<JIRA Worklog: id=u'374071'>, <JIRA Worklog: id=u'374364'>, <JIRA Worklog: id=u'374517'>, <JIRA Worklog: id=u'374819'>, <JIRA Worklog: id=u'374890'>, <JIRA Worklog: id=u'375013'>, <JIRA Worklog: id=u'375105'>, <JIRA Worklog: id=u'375347'>]
[<JIRA Worklog: id=u'374239'>, <JIRA Worklog: id=u'374240'>]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I want to do something like below piece of code :- want to iterate for number of worklogs entries for particular value.key
Code:-
i = 0
for value in issues_in_project:
for i in value:
print value.fields.worklog.worklogs[i].timeSpent, value.fields.worklog.worklogs[i].updated,value.fields.worklog.worklogs[i].updateAuthor,value.key
i = i + 1
Got error :-
Traceback (most recent call last):
File "jira_test_Time_log.py", line 89, in <module>
for i in value:
TypeError: 'Issue' object is not iterable
But I was able to get results from below for 2 indexes:-
for value in issues_in_project:
print value.fields.worklog.worklogs[0].timeSpent, value.fields.worklog.worklogs[0].updated,value.fields.worklog.worklogs[0].updateAuthor,value.key
print value.fields.worklog.worklogs[1].timeSpent, value.fields.worklog.worklogs[1].updated,value.fields.worklog.worklogs[1].updateAuthor,value.key
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.