Task Duration changes when assigned resource


#1

Hi,


I having problems with the task duration when I tried to set a resource which doesn’t last the whole task. I mean:
  • I want a task duration of 32 hours (4 days) which starts at a fixed date. Then I want to add a resource assignment just for 8 hours, starting the day 2 (then the res assignment will finish the same day (100%) ) and for the rest of task days I want 0h of resource but I want the task appears until the last day! . I want a fixed task duration and juste one day of resource assignment.
I have tried a lot of methods fixing all the task and resource parameters, but at every time the task duration changes (to 3 days) and I don’t want this.

What can I do? How can I avoid this dependance ? I noticed that automatic calculations are made to the Task once I set the resource assignment, before creating the xml. I don’t need calculations!

Do you know how?

Here is one of my codes:


Private Sub Writing()

Dim proj As New Project()
Dim preParent As New Aspose.Tasks.Task()

proj.StartDate = New DateTime(2000, 1, 1)
proj.MinutesPerDay = 8 * 60
proj.Calendar = Calendar.MakeStandardCalendar

For i As Integer = 1 To 10
Dim res As Aspose.Tasks.Resource = proj.AddResource("Person " & i)
Next

For i As Integer = 1 To 5

Dim ParentTask As Aspose.Tasks.Task = proj.AddTask("Example Task " & i)
ParentTask.OutlineLevel = 1
Dim Pred As New Aspose.Tasks.Task()
Pred.Duration = New TimeSpan(32, 0, 0)

For j As Integer = 1 To 10

Dim Subtask As Aspose.Tasks.Task = proj.AddTask(“Subtask " & j)
Dim dur = New TimeSpan(32, 0, 0)
'Subtask.ConstraintType = ConstraintType.MustFinishOn
Subtask.OutlineLevel = 2
Subtask.Duration = dur
Subtask.Type = TaskType.FixedDuration

'”“Subtask.IsEffortDriven() = False

Dim res = proj.Resources(j - 1)
Dim resAsg As ResourceAssignment = proj.AddResourceAssignment(Subtask, res)

resAsg.Work = New TimeSpan(8, 0, 0)
resAsg.PeakUnits = 1
resAsg.Delay = 4800

'”“resAsg.Start = Subtask.Start.AddDays(1)
'”"resAsg.Finish = Subtask.Start.AddDays(2)

If j = 1 Then
Pred = Subtask
Else
proj.AddTaskLink(New TaskLink(Pred, Subtask, TaskLinkType.FinishToStart))
Pred = Subtask
End If

Next j
If i = 1 Then
ParentTask.Start = proj.StartDate
preParent = ParentTask
Else
proj.AddTaskLink(New TaskLink(preParent, ParentTask, TaskLinkType.FinishToStart))
preParent = ParentTask
End If
Next i

proj.Save(“C:\output.xml”, Aspose.Tasks.Saving.SaveFileFormat.XML)

End Sub

#2

Hi Katherine,


I have analyzed the code and observed that you are linking the summary task with child tasks. I have slightly modified the code such that the duration does not change now by attaching the resources. Please give it a try and let us know the feedback.


Private Shared Sub Tasks574732()

Dim proj As New Project()

Dim preParent As New Aspose.Tasks.Task()


proj.StartDate = New DateTime(2000, 1, 1)

proj.MinutesPerDay = 8 * 60

proj.Calendar = Calendar.MakeStandardCalendar()


For i As Integer = 1 To 10

Dim res As Aspose.Tasks.Resource = proj.AddResource("Person " & i)

Next

For i As Integer = 1 To 5

Dim ParentTask As Aspose.Tasks.Task = proj.AddTask("Example Task " & i)


ParentTask.OutlineLevel = 1

Dim Pred As New Aspose.Tasks.Task()

Pred.Duration = New TimeSpan(32, 0, 0)



For j As Integer = 1 To 10

Dim Subtask As Aspose.Tasks.Task = proj.AddTask("Subtask " & j)

Dim dur As dynamic = New TimeSpan(32, 0, 0)

Subtask.OutlineLevel = 2

Subtask.Duration = dur

Subtask.Type = Aspose.Tasks.TaskType.FixedDuration


Dim res As Resource = proj.Resources(j - 1)

Dim resAsg As ResourceAssignment = proj.AddResourceAssignment(Subtask, res)



resAsg.Work = New TimeSpan(8, 0, 0)

'resAsg.PeakUnits = 1;

'resAsg.Delay = 480;

If j = 1 Then

Pred = Subtask

If i > 1 Then

proj.AddTaskLink(New TaskLink(proj.GetTaskById(Subtask.Id - 2), Subtask, TaskLinkType.FinishToStart))

End If

Else

proj.AddTaskLink(New TaskLink(Pred, Subtask, TaskLinkType.FinishToStart))

Pred = Subtask


End If

Next

If i = 1 Then

ParentTask.Start = proj.StartDate

preParent = ParentTask

Else

'proj.AddTaskLink(new TaskLink(preParent, ParentTask, TaskLinkType.FinishToStart));

preParent = ParentTask

End If

Next

proj.Save(“outputVerified.xml”, Aspose.Tasks.Saving.SaveFileFormat.XML)

End Sub

#3

Thank you for your answer kashif but it didn’t solve my problems:

  • The resource is automatically distributed for all the task duration
  • If I decrease the resource assignment duration, the task duration changes

What I want to do is shown by the image attached. And it is:

  • Fix tasks durations so that I can add a Resource Assignment with a duration smaller than the total task duration (see the picture) without changing the task duration!

Is that possible? I really need this to work if I want to buy the license.

And how can I do it? because assignment.Start/finish doesn’t have any effect, similar with start/finish dates in timphasedata.

Thank you !!


#4

Hi Katherine,


Thank you for providing more details. We are working on this requirement and will write back soon to share our findings.

Thank you for your patience and understanding in this regard.

#5

Hi Katherine,


Following is a sample that can be used to achieve the required functionality.

Private Shared Sub T1ByDeveloper()
Dim project As New Project()
project.StartDate = New DateTime(2014, 9, 24)
’ use helper method to add resource
Dim person1 As Resource = project.AddResource(“Person 1”)

’ don’t use recalculations at all set everything manually
Dim task1 As New Aspose.Tasks.Task(“Task 1”)
task1.Type = Aspose.Tasks.TaskType.FixedDuration
task1.DurationFormat = TimeUnitType.Day

Dim assn1 As New ResourceAssignment(task1, person1)
assn1.WorkContour = WorkContourType.Contoured
assn1.TimephasedData = New List(Of TimephasedData)()

Dim td As New TimephasedData()
td.Start = New DateTime(2014, 9, 24, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
assn1.TimephasedData.Add(td)

td = New TimephasedData()
td.Start = New DateTime(2014, 9, 25, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(7))
assn1.TimephasedData.Add(td)

td = New TimephasedData()
td.Start = New DateTime(2014, 9, 26, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(4))
assn1.TimephasedData.Add(td)

td = New TimephasedData()
td.Start = New DateTime(2014, 9, 29, 8, 0, 0)
td.Finish = td.Start.AddDays(1)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
assn1.TimephasedData.Add(td)

td = New TimephasedData()
td.Start = New DateTime(2014, 9, 30, 8, 0, 0)
td.Finish = td.Start.AddHours(9)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(6))
assn1.TimephasedData.Add(td)

td = New TimephasedData()
td.Start = New DateTime(2014, 9, 1, 8, 0, 0)
td.Finish = td.Start.AddHours(9)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(0))
assn1.TimephasedData.Add(td)

assn1.Work = InlineAssignHelper(task1.Work, TimeSpan.FromHours(17))
task1.Start = project.StartDate
task1.Finish = td.Finish
task1.Duration = project.Calendar.GetWorkingHours(task1.Start, task1.Finish).WorkingHours


project.RootTask.Children.Add(task1)
project.ResourceAssignments.Add(assn1)

’ recalculate
project.CalcResourceAssignmentIds()
project.CalcResourceAssignmentUids()
project.CalcTaskIds()
project.CalcTaskUids()
project.UpdateReferences()

project.Save(“D:\Aspose\saved.xml”, SaveFileFormat.XML)
End Sub

Private Shared Function TimeSpanToTDString(timeSpan As TimeSpan) As String
Return String.Format(“PT{0}H{1}M{2}S)”, timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds)
End Function

#6

First, thanks a lot for your reply! It was really helpful… but I still have some questions:

  • In ms Project the resource “person 1” is show at 42 000% . I’ve tried to modify the units, the work, peakunits but it doesn’t have any effect in the ms project. Is it possible disable these calculations?
  • Can you please refer me to anything which explains about calculations and dependencies? Because I don’t really understand data dependencies and which values have a higher priority.
  • This because in my cause all the project information is stocked in a database and I just want Ms Project to read it, without additional calculations. It works before when I was using Access databases *.mdb) to import/export projects into ms Projects but now, using XML, I having a lot of problems with automatic calculations.





#7

Hi Katherine,


We are sorry for a delayed response. We are working over your inquiry and will soon share our findings here with you. We appreciate your patience until then.


#8

Thanks,

I’ve modified a little the code so now the resource “person 1” is shown a 88% (which is correct)

For every timephasedata I speficied the time unit (hours) and for the finish data, I added 9 hours, not 1 day.

td = New TimephasedData()
td.Start = New DateTime(2014, 9, 25, 8, 0, 0)
td.Finish = td.Start.AddHours(9)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = TimeSpanToTDString(TimeSpan.FromHours(7))
td.Unit = TimeUnitType.Hour
assn1.TimephasedData.Add(td)


I’ll wait the the rest of the answers.


#9

Hi Katherine,


We are glad to know that your issue is resolved.

Regarding your other query, there are number of methods to achieve same result in Aspose.Tasks. One way is to use public constructors for main objects and after that invoking Calc… methods and UpdateReferences. Also special care is to be taken of correct Uids, Ids and references to ParentTask and ParentProject.

Other way is to use Project.Add… helper methods which do recalculations.

I would also like to share that if everything is set properly we can use Project.CalcualteAfterEdit flag. If set to true Project will do calculations after changing object values for example: Project.CalculateAfterEdit = true;


task.Start = task.Start.AddDays(1)

It will move all successors dates in the project and if Project.CalculateAfterEdit = false, then task.Start = task.Start.AddDays(1) will set only task.Start value.

Also, following is set of fields which Project.CalculateAfterEdit = true will recalculate:


Task fields
  • TaskStart
  • TaskFinish
  • TaskDuration
  • TaskRemainingDuration
  • TaskPercentComplete
  • TaskPercentWorkComplete
  • TaskWork
  • TaskActualDuration
  • TaskActualStart
  • TaskActualFinish
  • TaskActualWork
  • TaskCost
  • TaskFixedCost
  • TaskConstraintType
  • TaskConstraintDate
  • TaskStop
  • TaskOutlineLevel
  • TaskOvertimeWork
  • TaskActualOvertimeWork
  • TaskRemainingOvertimeWork
  • TaskOvertimeCost
  • TaskActualOvertimeCost
  • TaskRemainingCost
  • TaskRemainingOvertimeCost
  • TaskBudgetWork
  • TaskBudgetCost
  • TaskActive
  • TaskLevelingDelay

Resource fields
  • RscCost
  • RscOvertimeCost
  • RscActualCost
  • RscActualOvertimeCost
  • RscRemainingCost
  • RscRemainingOvertimeCost
  • RscWork
  • RscOvertimeWork
  • RscActualWork
  • RscActualOvertimeWork
  • RscRemainingWork
  • RscRegularWork
  • RscRemainingOvertimeWork
  • RscWorkVariance
  • RscCostVariance
  • RscStandardRate
  • RscOvertimeRate
  • RscCostPerUse
  • RscType
Assignment fields
  • AssignmentWork
  • AssignmentRemainingWork
  • AssignmentRegularWork
  • AssignmentActualWork
  • AssignmentOvertimeWork
  • AssignmentActualOvertimeWork
  • AssignmentRemainingOvertimeWork
  • AssignmentUnits
  • AssignmentCost
  • AssignmentRemainingCost
  • AssignmentActualCost
  • AssignmentOvertimeCost
  • AssignmentActualOvertimeCost
  • AssignmentRemainingOvertimeCost
  • AssignmentBudgetCost
  • AssignmentBudgetWork
  • AssignmentWorkContour
  • AssignmentPercentWorkComplete
  • AssignmentActualStart
  • AssignmentActualFinish
  • AssignmentDelay

Please feel free to write us back if you have any other query related to Aspose.Tasks.

#10

Thanks kashif, it is much clear now. Even though, I have another problem.

  • When I was trying to create the timephasedata of all the assignments of my project (which its information is stocked in a database), I noticed that even if the XML where correct, MS Project didn’t show any timephasedata, except the first one, and not correctly.
  • So I took the example code you send me last time and I tried to add a new task, a new assignment and a new timphasedata list to this assignment but… I don’t know why, it doesn’t work. The tasks durations are set correctly, also the assigments work, but the timpahsedata is just shown for the first assignment but this timephasesed data correspond to the second assignment. So the second one re-writes the fist one. The XML seems correct so I don’t understand why this is happening.

Can you please check and help me with this? Thanks

Here is the code:

Public Sub T1ByDeveloper()
Dim project As New Project()

project.StartDate = New DateTime(2014, 9, 1)
'project.CalculateAfterEdit = False
project.Calendar = Calendar.MakeStandardCalendar

Dim person1 As Resource = project.AddResource(“Person 1”)
Dim person2 As Resource = project.AddResource(“Person 2”)

'dont use recalculations at all, set everything manually
Dim task1 As New Aspose.Tasks.Task(“Task1”)
task1.Type = Aspose.Tasks.TaskType.FixedDuration
task1.DurationFormat = TimeUnitType.Day

Dim assn1 As New ResourceAssignment(task1, person1)
assn1.WorkContour = WorkContourType.Contoured
assn1.TimephasedData = New List(Of TimephasedData)()

Dim td As New TimephasedData()
td.Start = New DateTime(2014, 10, 1, 8, 0, 0)
td.Finish = New DateTime(2014, 10, 31, 17, 0, 0)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = “PT200H0M0S”
td.Unit = TimeUnitType.Month
assn1.TimephasedData.Add(td)

td = New TimephasedData()
td.Start = New DateTime(2014, 11, 1)
td.Finish = New DateTime(2014, 11, 30)
td.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td.Value = “PT50H0M0S”
td.Unit = TimeUnitType.Month
assn1.TimephasedData.Add(td)

assn1.Work = InlineAssignHelper(task1.Work, TimeSpan.FromHours(250))
task1.Start = project.StartDate
task1.Finish = New DateTime(2014, 12, 31, 17, 0, 0)
task1.Duration = project.Calendar.GetWorkingHours(task1.Start, task1.Finish).WorkingHours

Dim task2 As New Aspose.Tasks.Task(“Task2”)
task2.Type = Aspose.Tasks.TaskType.FixedDuration
task2.DurationFormat = TimeUnitType.Day
Dim assn2 As New ResourceAssignment(task2, person2)
assn2.WorkContour = WorkContourType.Contoured
assn2.TimephasedData = New List(Of TimephasedData)()

Dim td2 As New TimephasedData()
td2.Start = New DateTime(2014, 9, 1)
td2.Finish = New DateTime(2014, 9, 30)
td2.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td2.Value = “PT50H0M0S”
td2.Unit = TimeUnitType.Month
assn2.TimephasedData.Add(td2)

td2 = New TimephasedData()
td2.Start = New DateTime(2014, 10, 1, 8, 0, 0)
td2.Finish = New DateTime(2014, 10, 31, 17, 0, 0)
td2.TimephasedDataType = TimephasedDataType.AssignmentRemainingWork
td2.Value = “PT100H0M0S”
td2.Unit = TimeUnitType.Month
assn2.TimephasedData.Add(td2)

assn2.Work = InlineAssignHelper(task2.Work, TimeSpan.FromHours(150))
task2.Start = project.StartDate
task2.Finish = New DateTime(2014, 11, 30, 17, 0, 0)
task2.Duration = project.Calendar.GetWorkingHours(task2.Start, task2.Finish).WorkingHours

project.RootTask.Children.Add(task1)
project.RootTask.Children.Add(task2)
project.ResourceAssignments.Add(assn1)
project.ResourceAssignments.Add(assn2)

’ //// Recalculations
project.CalcResourceAssignmentIds()
project.CalcResourceAssignmentUids()
project.CalcTaskIds()
project.CalcTaskUids()
project.UpdateReferences()

End Sub




#11

Found it!!!

I have to assign a UID to each td which must be the assigment UID. (td.Uid = assignment.Uid)


#12

Hi Katherine,

Thank you for sharing the updated feedback and please feel free to write to us in case you have any additional query related to Aspose.Tasks for assistance.


#14

@IshuAbrol,

Thank you for contacting Aspose support team.

We are analyzing this issue and are not able to compile it due to missing definition of “OneMin” and “OneHour”. Please provide their definition to compile the code.

Another anomaly is observed where you are creating new calendar “Calendar1”. Here when you create new calendar, it contains a collection WeekDays by default counting to 7. When you use cal.getWeekDays().add(WeekDay.createDefaultWorkingDay(...)), it adds 7 more weekdays and total counts to 14 weekdays in this calendar. It may be causing issue while performing this task.
Please clear the previous collection as mentioned below:

com.aspose.tasks.Calendar cal = project.getCalendars().add("Calendar1");
cal.getWeekDays().clear();//NOTE THIS LINE

And just for your reference you may visit following link as well which discussed about using three-letters time zone IDs.
Java calendar wrong time for PST timezone

Please feel free to share your feedback and any further query in this regard.


#16

@IshuAbrol,

Thank you for contacting Aspose support team again.

You have not sent the MPP but images only. Please send us complete program which can be compiled and executed here without any missing reference. Also send us template MPP file, the output file, Aspose.Tasks library version used for testing and one expected output MPP file which is created using Microsoft Project. It will help us to compare the output with the desired output and provide assistance accordingly.


#18

@IshuAbrol,

We are working on this issue and will share our feedback soon.