Namrata
Namrata

Reputation: 41

RTC query to get each day effort

How to query in RTC 7.0.2 for a formal project, to get each day effort (time tracking) or time spent each day for a task?

Upvotes: 1

Views: 225

Answers (1)

VonC
VonC

Reputation: 1328192

That might have changed since 2015, but this thread mentioned

Time tracking is not a field/an attribute. Time tracking entries are added to a work item using a reference/link. I know that others have done this in the past.

The article which deals with this topic is "The Work Item Time Tracking API" from Ralph

The following code update or create time tracking entries, but, in the process, access and read existing time tracking first, which is of interest here.

public void updateOrCreateTimeSheetEntry(WorkItemWorkingCopy workingCopy,
        ITimeCode timeCode, Timestamp startDateTimeStamp,
        Duration workDuration, Identifier workType,
        IProgressMonitor monitor) throws TeamRepositoryException {

    // set the active work item from the working copy
    setWorkItem(workingCopy.getWorkItem());

    // Find a matching time sheet if it exists.
    ITimeSheetEntry timeSheet = findTimeSheetEntry(timeCode,
            startDateTimeStamp, monitor);
    if (timeSheet == null) {
        // There is no time sheet for this entry
        // Create a new one and create the link
        timeSheet = createTimeSheet();
        workingCopy.getReferences()
                .add(WorkItemEndPoints.WORK_TIME,
                        IReferenceFactory.INSTANCE
                                .createReferenceToItem(timeSheet));
        // Add the entry to the map to hold the data
        addEntry(timeSheet, monitor);
    } else {
        // There is a time sheet, we need to update it
        // Get the workingCopy of the time sheet
        timeSheet = (ITimeSheetEntry) timeSheet.getWorkingCopy();
        // remove the time spent from current time
        setTotalDuration(new Duration(getTotalDuration().longValue()
                - timeSheet.getTimeSpent().longValue()));
    }

    // Set the new data
    timeSheet.setStartDate(startDateTimeStamp);
    timeSheet.setTimeCodeId(timeCode.getTimeCodeId());
    // TODO: If I leave this out it fails....
    timeSheet.setTimeCode(timeCode.getTimeCodeLabel());
    timeSheet.setTimeSpent(workDuration);
    timeSheet.setWorkType(workType);
    // add the new time back
    setTotalDuration(getTotalDuration().add(workDuration));
    // Update the value
    // Note: it is important to set the duration value, of the work item
    // otherwise the work item is not marked as dirty and in need to update
    // in the repository and the save process will not save the time sheet
    getWorkItem().setDuration(getTotalDuration().longValue());
    workingCopy.getDependentItems().add(timeSheet);
}

You can make a query to fetch work items for a given date, used a stored query, and list your work items that way.

Upvotes: 0

Related Questions