Adding Resources to a subtask defaults duration to 0

Good morning. I've been working with Aspose.Task for .Net.

I'm pulling information from a database and creating a project based on that information.

The information is three levels deep. Project, Task, and subtask. I populate the Project with info, fill out it's children (Task), and then fill out it's children, children. I run into a weird issue. Once I input the information, after I calculate TaskID, TaskUID, ResourceID, ResourceUID; it seems when subtask are populated with a resource, the duration goes to 0. Conversely, if I leave resources empty for subtask, the duration populates just fine. Attached is a coding sample.

try

{

oProject = new Aspose.Tasks.Project();

oProject.DurationFormat = TimeUnitType.Day;

oProject.MinutesPerDay = 480;

int wbsIndex = 0;

int taskIndex = 0;

Task root = new Task();

oProject.RootTask = root;

foreach (TaskLTO t in this.TaskCollection)

{//collection is already in order, just build

Aspose.Tasks.Task newTask = new Aspose.Tasks.Task();

++taskCount;

newTask.Uid = t.Index;

newTask.Id = taskCount;

newTask.Name = t.Task;

newTask.ActualStart = t.Start;

newTask.Duration = new TimeSpan(Int32.Parse(t.Finish.Subtract(t.Start).Days.ToString()) * 8,0,0);

newTask.DurationFormat = TimeUnitType.Day;

newTask.OutlineLevel = (int)t.TaskType;

//build outline of task

switch (t.TaskType)

{

case TaskTypes.PM_WBS:

{

root.Children.Add(newTask);

break;

}

case TaskTypes.Task:

{

wbsIndex = root.Children.Count - 1;

((Task)root.Children[wbsIndex]).Children.Add(newTask);

break;

}

case TaskTypes.SubTask:

{

taskIndex = ((Task)root.Children[wbsIndex]).Children.Count - 1;

((Task)((Task)root.Children[wbsIndex]).Children[taskIndex]).Children.Add(newTask);

break;

}

}

//determine if this resource is unique...if so, add them to the resource list, otherwise keep it moving

if (t.Resources != "")

{//adds resource to the projec

AddResource(ref oProject, t.Resources);

}

}

oProject.CalcTaskIds();

oProject.CalcTaskUids();

//run through again to make task links...predecessors

//foreach (TaskLTO taskLTO in this.TaskCollection)

// {

// if (taskLTO.Predecessors > 0)

// {//create link

// Task task1 = oProject.GetTaskById(taskLTO.Index);

// Task task2 = oProject.GetTaskById(this.GetTaskLTOByTypeAndID(taskLTO.Predecessors, taskLTO.TaskType).Index);

// oProject.TaskLinks.Add( new TaskLink(task1, task2, TaskLinkType.StartToFinish));

// }

// }

//I initially used recursion here to create the appropriate relationships between task and resources...this however screwed up the duration; everything being set to 0

foreach (Task wbs in oProject.RootTask.Children)

{

foreach (Resource res in oProject.Resources)

{

if ((this.TaskCollection.Count >= wbs.Id - 1) && (this.TaskCollection[wbs.Id - 1].Task != "") && (res.Name == this.TaskCollection[wbs.Id - 1].Resources))

{

//this.AddResourceAssignment(ref oProject, wbs, res);

oProject.ResourceAssignments.Add(new ResourceAssignment(wbs,res));

}

}

foreach (Task task in wbs.Children)

{

foreach (Resource res in oProject.Resources)

{

if ((this.TaskCollection.Count >= task.Id - 1) && (this.TaskCollection[task.Id - 1].Task != "") && (res.Name == this.TaskCollection[task.Id - 1].Resources))

{

//this.AddResourceAssignment(ref oProject, wbs, res);

oProject.ResourceAssignments.Add(new ResourceAssignment(task,res));

}

}

}

}

//create relationships between resources and tasks...resource assignments.

oProject.CalcResourceAssignmentUids();

oProject.CalcResourceAssignmentIds();

// oProject.CalcResourceFields();

// oProject.CalcResourceStartFinish();

//the world is good and just...generate document

return GenerateFile(ref oProject);

When i refrain from Calculating Resources and Task, the duration doesn't get set but the Resources are preserved.

Hello Thomas,

1) Refer to your yesterday's post about the damaged file and our chat on live support. I have investigated the issue and found that the error message was raised due to some tasks finish date exceeded project finish date. So it will be the best practice to set the project finish date greater than the max finish date of the tasks using Project.FinishDate property. Also, you will get the exact start and finish dates if you set the start date with complete information about date as well starting working time like this:

tsk1.ActualStart = DateTime.Parse("30-Oct-2009 08:00 AM");

2) I shall investigate the issue of duration changing to 0 when task is assigned to a resource and let you know soon about the results.

Thank you,

I appreciate your help. I've been banging my head on this all night (literally). I created a recursive function to transverse the Task tree creating relationships between task and resources where warranted. For some reason, when relationship assignments were created for subtask, the duration would plummet to zero. When I didn't set the subtask, the duration would remain intact. It was the strangest thing.

I've attached the object that was created to process the information coming from the database. If I'm doing something wrong in my coding, please let me know. I'm following the samples provided; but ...so far I've only had marginal success.

One more thing. I'm attaching two xml documents to give an example of the above. One has resources populated but no duration on the subtask. The other is missing resources for the subtask, but allows the subtask to maintain duration.

The only difference in the code is adding resources to subtask and creating the relationship using the resource assignments.

Hi Thomas,

Discussed in this thread created by you.

Hi Thomas,

A complete example has been posted in this thread.

Hi Thomas,

The only issue left is now that the first Resource object in the Resources collection of a Project object is ignored. This issue has been created with issue id 11600 and you will be informed in this thread as soon as it is resolved.

The issues you have found earlier (filed as 11600) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

Hi,

I have run into the problem of the task duration = 0. (especially when the task is complete).

I have found that when I added a default calendar to the task and started to set the resourceassignment 'remainingwork' to the task duration (or calculated work) the duration started to appear.

I was unable to set the other work related properties for the resourceassignments (such as budgetedwork, work, regularwork ...). for some reason they always show zero value.

Regards, Bruce

Hi Bruce,

Can you please verify that same properties can be set accordingly when the said file is accessed through MS Project? I am just asking because, it is possible that there may be wrong sequence of events in the said project.

Hi,

I've attached the MPP file created by the application. (Example Project).

One of the differences between MSP automation and aspose is the handling of defaults. I essentially just add a new assignment to a task ... this operation automatically sets reasonable defaults - eg. work, dates ... I do know that effort driven tasks cause a bit of a challenge - however, it is at least understandable.

With Aspose.Tasks, I seem to need to understand what settings would have been set to recreate the correct settings on the assignments.

If it would help, I'm happy to provide the two classes (mpp automation and aspose.tasks) that implement the interface. I don't claim they are perfect ... they are where they are.

Regards, Bruce

Hi Bruce,

Can you please provide the source code as well, so that we can understand and investigate the problem in right direction?

Hi,

Here is the code I currently use to add resource assignments:

'add any assignments that need to be added

If plngResAsnToSet >= clngZero Then

For plngIDX = clngZero To plngResAsnToSet

If rarrAssign(plngIDX).alngRESUID <> clngMinOne Then

'create a resource

presForAsn = mprjDocument.GetResourceByUid(rarrAssign(plngIDX).alngRESUID)

'create an assignment

pasnToGet = New Aspose.Tasks.ResourceAssignment(ptskToUse, presForAsn)

If pasnToGet IsNot Nothing Then

'have an assignment to add

mprjDocument.ResourceAssignments.Add(pasnToGet)

pasnToGet.Units = 1.0

'set the work for this task

pasnToGet.Start = ptskToUse.Start '(03)

pasnToGet.RemainingWork = ptskToUse.Duration '(04)

pasnToGet.Finish = ptskToUse.Finish '(03)

'pasnToGet.RegularWork = ptskToUse.Duration

'pasnToGet.RegularWork = ptskToUse.Calendar.GetWorkingHours(ptskToUse.Start, ptskToUse.Finish).WorkingHours

'pasnToGet.RemainingWork = ptskToUse.Duration

'OLD mprjDocument.CalcResourceAssignmentUids()

pasnToGet.Uid = mprjDocument.NextResourceAssignmentUid

'actual dates (for 02)

pasnToGet.ActualStart = ptskToUse.ActualStart

pasnToGet.ActualFinish = ptskToUse.ActualFinish

End If

End If

Next

End If

The attached results files were created as follows:

EventDP2Test021CleanRT00 --> round trip initial data export

EventDP2Test021CleanRT01 ..> Export with all Actual, start / finish, work commented out. The Task start and end dates have already been set so the task should have some duration.

NOTE: zero duration shown for Tasks that have been completed ... all others have duration (probably could have gone back further).

EventDP2Test021CleanRT02 --> added back two lines to set actualstart and actualfinish

NOTE: All zero durations now gone by adding the actual dates for completed items.

EventDP2Test021CleanRT03 --> added start and end dates for the assignment

Note: no change in duration - no work allocated to the resource

EventDP2Test021CleanRT04 --> set remaining work to task duration

Note: work always now set to 24hours - even though duration is not always 24 hours?

This has helped me understand a little more about setting the work for an assignment. As you can see in the comments, I also attempted to use the .getworkinghours for the task start and end dates. It did not seem to be any better than using the duration ... I'll keep looking at this. Or any guidance appreciated.

The calculations in the area of work need to be accurate. (cost and resource information are derived from these items).

Hope this helps... I'll be glad to provide more info if necessary.

Regards, Bruce

Hi Bruce,

I am investigation the issue and will get back to you in a couple of days.

Hello Bruce,


Your question looks more complicated than expected. It is not related to our code but we should investigate MS Project behaviour.

Solution of the sort of this puzzle will take some additional time.

I am coming back to you next year:)

Hi Bruce,


We have decided to create an issue for the problem. The issue ‘MS Project durations, works and costs settings and recalculation.’ with issue id = 13140 was created and linked to this forum thread.

Hi Bruce,

Sorry for long delay. I have created a sample for setting a task’s duration for partly completed task.

The sample creates a project with 3 tasks of all possible types (fixed duration, fixed work and fixed units), 20% of each task was completed. You can find the sample in the attachments (there are two versions for C# and Visual Basic, use any). Complete information about actual durations you can find at Actual Duration (task field) - Microsoft Support.

The issues you have found earlier (filed as ) have been fixed in this Aspose.Words for JasperReports 18.3 update.