Post

2 followers Follow
0
Avatar

Timesheet query?

Hi - I'm new to the API, looking for some sample code on how to get timesheet data.  Specifically, I need to be able to get all hours for a specific project, in a specific timeframe.  

If anyone has done anything like this, I'd really appreciate some pointers.

Import from old forum Answered

Please sign in to leave a comment.

3 comments

0
Avatar

I have - honestly it's kinda rough.  I searched the whole PDF document for "Timesheet" and it came up empty.  Your API reference has a copyright date of 2008, and not any more usable information than Intellisense.  So any help would be greatly appreciated.

Import from old forum 0 votes
Comment actions Permalink
0
Avatar

Hi Tracy.

Try this (change the Id of the project and the date condition according to your needs):

            EntityQuery enQ = new EntityQuery

            {

                TypeName = "Timesheet",

                Fields = new string[] { "ReportedDate", "Reportedby.displayname", "Duration", "WorkItem.Name", "WorkItem.Project.Name" },

                Where = new And

                {

                    Conditions = new Compare[]

                    {

                        new Compare

                        {

                            LeftExpression = new FieldExpression { FieldName = "WorkItem" },

                            Operator = Operator.In,

                            RightExpression = new QueryExpression 

                            {

                                Query = new EntityQuery

                                {

                                    TypeName = "WorkItem",

                                    Where = new Compare

                                        {

                                            LeftExpression = new FieldExpression {FieldName = "Project"},

                                            Operator = Operator.Equal ,

                                            RightExpression = new ConstantExpression { Value = new EntityId {TypeName="Project", Value = "500b0bc763fc44f3af7b30e338a00a6a"}}

                                        }

                                }

                            }

                        },

                        new Compare

                        {

                            LeftExpression = new FieldExpression { FieldName = "ReportedDate" },

                            Operator = Operator.GreaterThanOrEqual,

                            RightExpression = new ConstantExpression { Value = new DateTime (2011,1,1)}

                        }

                    }

                }

            };

            var tsResult = service.Execute(new BaseMessage[] { enQ });

            var TimesheetEntries = tsResult[0].Success ? (tsResult[0] as QueryResult).Entities : null;

}

Hope this helps.

Ophir

Clarizen Team 0 votes
Comment actions Permalink