Friday, March 30, 2007

PS2007 Task Duration Calculation (based on Days)

This is just a short blog to comment on a little problem I recently ran into regarding updating the duration for a task using the PSI. The problem was 8 inches from the screen (i.e. me) however I thought I would blog about it to save someone else the problem (embarrassment). When adding a task duration to the ProjectDataset.TaskRow object the figure has to represent tenths of minutes as specified in the SDK class documentation. Here is a complete copy of my CreateTask function. Please note the example is written in C# and based on a strongly typed TaskDetails object.

public static void CreateTask(Proxy.ProjectDataSet dataset, int projNum, Proxy.TaskInfo TaskDetails, string name, Guid taskGuid)
{
Proxy.ProjectDataSet.TaskRow taskRow = dataset.Task.NewTaskRow();
taskRow.PROJ_UID = dataset.Project[projNum].PROJ_UID;
taskRow.TASK_UID = taskGuid;
TimeSpan span = TaskDetails.EndDate.Subtract(TaskDetails.StartDate);
int Days = span.Days;
taskRow.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day;
taskRow.TASK_DUR = (Days * 4800);
taskRow.TASK_NAME = name;
taskRow.TASK_START_DATE = TaskDetails.StartDate;
taskRow.TASK_FINISH_DATE = TaskDetails.EndDate;
//TaskDetails.Config_Position;
taskRow.TASK_PRIORITY = int.Parse(TaskDetails.Priority);
//TaskDetails.Project_Code;
taskRow.TASK_CONTACT = TaskDetails.TaskOwner;
//TaskDetails.WO_Code;
dataset.Task.AddTaskRow(taskRow);
}


Please note that line taskRow.TASK_DUR_FMT = (int)PSLibrary.Task.DurationFormat.Day only specifies how the duration will be displayed in the Project Server interfaces (PWA & Project Prof).

The 4800 figure should be changed based on the standard working hours in your project calendar. If the calendar used has a different number of working hours you will need to update this figure based on the following calculations:.

Here is how you get to 4800 to represent tenths of a minute.
Standard calendar = 8 hrs per day

8 Hours = 480 minutes

X10 = 4800 tenths of minutes

This presents a problem with maintainability but that is a configuration issue and something you will need to handle separately.