Post

1 follower Follow
0
Avatar

Querying Timesheet entries for a specific user

Given a known userID and taskID, what would be the appropriate query to read timesheet entries for a specific user? As of now I have a TimesheetViewQuery which I can specify a specific time and userID which returns an array of tasks for that user for that time period, but, this contains only information about the tasks, total time spent on it and such, but never actual values for specific entries. I also attempted to use a TimesheetQuery instead and pass in the array of Task ID's using query.setWorkItems, but, this Query always fails to return the expected entities. So, given those two values, what Query would I need to run against Clarizen's API to return a specific entry for Day X on Task Y? And, if possible, how to set those entries as well. 

 

Thanks.

 

Daniel Minion Answered

Please sign in to leave a comment.

8 comments

0
Avatar

Hi Daniel.

As you figured, the TimesheetViewQuery returns the relevant work items only, to be filled into a TimesheetQuery for example.

If you know the work items IDs you could use the TimesheetQuery directly (or the more general EntityQuery).

The TimesheetQuery is the one to use for your purpose (possibly following a TimesheetViewQuery).

However, you mentioned TimesheetQuery did not return the expected entities. This may be a permission issue. Timesheet entries retrieved through the API are according to the user's (logged into to the API) permissions.

To check for permissions, login to Clarizen with the same credentials and check if the expected entries are available there.

If you need access to all timesheet entries in the system, try using a super user's credentials.

If you think permissions is not the reason, I'll need specific information about the way you used TimesheetQuery (a code snippet is best) and what results were not returned.

Hope this helps.

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Thanks for the response Ophir, 

The code that contains both queries is here: http://pastebin.com/djSFPtpa - Not shown there is the user login/session setup, but, I presume both are working correctly since TimesheetViewQuery returns expected values. As of now, the array "results" contains all 11 tasks that I can view on Clarizen's page. I then initialize a new TimesheetQuery, build an array of all the ID's from the returned "Task" values on the previous query and add that to TimesheetQuery via "setWorkItems", and then I've added just a few fields I'd like to see returned back for each entry. However, nothing is ever populated in "resultt"'s (The ArrrayOfResult declared just before TimesheetQuery is executed) localBaseEntity value. 

Now, the only possible error I can see so far is that TimesheetQuery is expecting an ID for a WorkItem, not a Task ID which is what I am giving it. If that is the case, what would be the applicable field in the original TimesheetViewQuery to retrieve the array of WorkItem's for a given task?

 

Thanks again Ophir. 

Daniel Minion 0 votes
Comment actions Permalink
0
Avatar

Hi Daniel.

Your code seems to correct basically, the entity IDs can be Task IDs.

Please note, that TimesheetViewQuery returns all tasks that are reportable for the period. But that doesn't mean any timesheet were actually reported for these. Were any timesheet entries actually reported for those 11 tasks?

By the way, I saw you were not filtering the TimesheetQuery by the ReportedDate field, so expected results are all timesheet entries ever reported for these tasks.

If you write a few words about the scenario you're trying to implement, I may give you some tips on the best way to find the timesheet entries you're searching for.

Hope this helps

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

I'm actually using my own personal timesheet for this thus far, and, have time entries for all working days on 4 of those tasks for the requested date range. I presume that hours entered into tasks and submitted for approval would count as timesheet entries, correct?  

I also had a where condition  for TimesheetQuery that would filter out specific tasks by reported dates, but, I've removed that for now whilst I was trying to debug why I wasn't getting expected, or for that matter, *any* results from TimesheetQuery. 

Essentially what I'm looking to do is to increment certain timesheet entries from our own internal tool. So, say a user writes in our tool they worked for five hours on Task X, our tool would then enter 5 hours into their timesheet for Task X on that day. 

Thanks again for the help Ophir. 

Daniel Minion 0 votes
Comment actions Permalink
0
Avatar

Hi Daniel.

I cannot figure out why the TimesheetQuery you used returns no results. Your code seems correct and I successfully tried a similar scenario on my account.

It may be a bug on Clarizen side, but to further investigate, I will need your Clarizen credentials.

Please email them to Ophir.kenig@clarizen.com if you can. As you can figure, I am a Clarizen employee, and I will only use them to investigate the issue.

If sending your credentials is a problem, I have 2 more suggestions:

  1. Use EntityQuery instead of TimesheetQuery.
  2. Try to setup the Paging object with a page size of 1,000 on the TimesheetQuery

Hope this helps

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Hi Ophir,

I believe I just realized the cause of my problems. I was not aware that Clarizen used a zero-indexed Calendar, and thus when I was specifying dates it was always reporting a month in advance, and therefore there *weren't* any timesheet entries. I didn't realize either that if I do not give it a where condition, it will also not report anything back. Changing both of these, I am now seeing all my timesheet entries returned as expected.

Thank you very much for your help Ophir,

-Daniel

Daniel Minion 0 votes
Comment actions Permalink
0
Avatar

Hi Daniel!

Thanks for sharing your solution. 

I'm not a Java expert myself, but our API samples use a GregorianCalendar for dates. Perhaps that would give a more comprehensible experience. 

There's something I don't understand about your solution. Did you mean dates went wrong and a condition must be specified for TimesheetViewQuery? And as results from that pointed you to the wrong work items the TimesheetQuery returned nothing?

I want to verify that was the scenario, because your sample had no date conditions on the TimesheetQuery and TimesheetQuery does work with only work item ids for a condition.

 

Thanks again for sharing

 

Ophir Kenig 0 votes
Comment actions Permalink
0
Avatar

Whilst not shown in the code I posted, I was using setStartDate and setEndDate on the TimesheetViewQuery using two Calendar objects which were later passed onto a where condition in TimesheetQuery (I had this removed when I sent the code to you). Even though I was querying into the future (One month), the tasks were still available to me for next month so I was unaware the dates were not correct. I had actually put the setWhere condition back on the TimesheetQuery and given it a much greater time range to see what would happen and thats when I started seeing results back. I now realize that this is because the Calendar I was using also indexes from zero as well.  Whoops. 

Thanks again Ophir.

Daniel Minion 0 votes
Comment actions Permalink