How to write the OutlineLevel using CalcTaskxx

If I call CalcTaskIds and CalcTaskUids after setting the Task.OutLineLevel.Property value, the value is set to “1”.
This problem was treated in a old post (<a href="https://forum.aspose.com/t/4858#576371)

      • So, how do I set the outlinelevel? There are more than 2 levels!

My code is a loop. Tasks information is stored in a database table, including outline level/number, summary task. So I read each line (each task) and add the task to a the project : project.RootTask.Children.Add(taskMSP)

Do While Not adoORACLE.EOF
Dim taskMSP As New Aspose.Tasks.Task
'taskMSP = prjMSP.AddTask()
taskMSP.Id = adoORACLE(“TASK_ID”).Value
taskMSP.Uid = adoORACLE(“TASK_UID”).Value
taskMSP.Name = adoORACLE(“TASK_NAME”).Value
taskMSP.Type = adoORACLE(“task_type”).Value
If Not IsDBNull(adoORACLE(“TASK_CONSTRAINT_TYPE”).Value) Then taskMSP.ConstraintType = adoORACLE(“TASK_CONSTRAINT_TYPE”).Value
If Not IsDBNull(adoORACLE(“TASK_CONSTRAINT_DATE”).Value) Then taskMSP.ConstraintDate = adoORACLE(“TASK_CONSTRAINT_DATE”).Value

If IsDBNull(adoORACLE(“TASK_DUR”).Value) = False Then
If adoORACLE(“TASK_DUR”).Value = 0 And adoORACLE(“TASK_IS_MILESTONE”).Value = 0 Then
taskMSP.Duration = New TimeSpan(0, 0, 1)
Else
taskMSP.Duration = New TimeSpan(adoORACLE(“TASK_DUR”).Value / 10 / 60, 0, 0)
End If
taskMSP.DurationFormat = TimeUnitType.Day
End If

taskMSP.Start = adoORACLE(“TASK_START_DATE”).Value
taskMSP.Finish = adoORACLE(“TASK_FINISH_DATE”).Value
taskMSP.OutlineLevel = adoORACLE(“task_outline_level”).Value
If Not IsDBNull(adoORACLE(“task_is_summary”).Value) Then taskMSP.DisplayAsSummary = adoORACLE(“task_is_summary”).Value

'Not baseline???
If IsDBNull(adoORACLE(“task_act_start”).Value) = False And IsDBNull(adoORACLE(“task_act_finish”).Value) = False Then
taskMSP.ActualStart = adoORACLE(“task_act_start”).Value
taskMSP.ActualFinish = adoORACLE(“task_act_finish”).Value
taskMSP.PercentComplete = adoORACLE(“task_pct_comp”).Value
End If
taskMSP.IsMilestone = adoORACLE(“task_is_milestone”).Value
taskMSP.IsEffortDriven = adoORACLE(“task_is_effort_driven”).Value
If Not IsDBNull(adoORACLE(“task_is_rolled_up”).Value) Then taskMSP.IsRollup = adoORACLE(“task_is_rolled_up”).Value

prjMSP.RootTask.Children.Add(taskMSP)
adoORACLE.MoveNext()
Loop





Hi Katherine,


Please spare us little time as we are working on this issue and will share our feedback soon.

Hi Katherine,


Thank you for your patience.

I have analyzed your requirements and code and following are the suggestions:

  1. For a task, Start Date and Duration are sufficient as Finish date is automatically calculated. Therefore it is suggested that just provide task start date and duration.
  2. Constraints should be applied wherever required like if you want to start particular task on a defined date, use ConstraintType.StartNoEarlierThan and provide constraint date as well.
  3. Parent child relationship among the tasks should be maintained like if some task is at OutlineLevel 1, it should be added to Project.RootTask.Children. Similarly if some task it at OutlineLevel greater than 1, then its parent task id should be known so that it can be added to the children of that particular task and not the project root task. You may please organize the database such that for task at OutlineLevel greater than 1, there should be link to parent task.

Following is a sample code which creates project with multiple tasks and upto OutlineLevel 4. Could you please give it a try and let us know your feedback? Output of the code can be viewed here: http://prntscr.com/4sjstu.

static void TASK576984()
{
Project prj = new Project();

Aspose.Tasks.Task t1 = new Aspose.Tasks.Task();
t1.Name = “SummaryTask12”;
t1.Start = new DateTime(2014,10,6);
t1.Duration = new TimeSpan(16,0,0);
t1.OutlineLevel = 1;
t1.ConstraintType = ConstraintType.StartNoEarlierThan;
t1.ConstraintDate = t1.Start;
t1.DurationFormat = TimeUnitType.Day;
prj.RootTask.Children.Add(t1);


Aspose.Tasks.Task t2 = new Aspose.Tasks.Task();
t2.Name = “Task 1”;
t2.Start = new DateTime(2014, 10, 6);
t2.Duration = new TimeSpan(16, 0, 0);
t2.OutlineLevel = 2;
t2.ConstraintType = ConstraintType.StartNoEarlierThan;
t2.ConstraintDate = t2.Start;
t2.DurationFormat = TimeUnitType.Day;
t1.Children.Add(t2);


Aspose.Tasks.Task t3 = new Aspose.Tasks.Task();
t3.Name = “Task 2”;
t3.Start = new DateTime(2014, 10, 7);
t3.Duration = new TimeSpan(8, 0, 0);
t3.OutlineLevel = 2;
t3.ConstraintType = ConstraintType.StartNoEarlierThan;
t3.ConstraintDate = t3.Start;
t3.DurationFormat = TimeUnitType.Day;
t1.Children.Add(t3);

  Aspose.Tasks.Task t4 = <span class="kwrd">new</span> Aspose.Tasks.Task();<br>      t4.Name = "SummaryTask3To6";<br>      t4.Start = <span class="kwrd">new</span> DateTime(2014, 10, 8);<br>      t4.Duration = <span class="kwrd">new</span> TimeSpan(8, 0, 0);<br>      t4.OutlineLevel = 1;<br>      t4.ConstraintType = ConstraintType.StartNoEarlierThan;<br>      t4.ConstraintDate = t4.Start;<br>      t4.DurationFormat = TimeUnitType.Day;<br>      prj.RootTask.Children.Add(t4);<br>


Aspose.Tasks.Task t5 = new Aspose.Tasks.Task();
t5.Name = “Task 3”;
t5.Start = new DateTime(2014, 10, 8);
t5.Duration = new TimeSpan(8, 0, 0);
t5.OutlineLevel = 2;
t5.ConstraintType = ConstraintType.StartNoEarlierThan;
t5.ConstraintDate = t5.Start;
t5.DurationFormat = TimeUnitType.Day;
t4.Children.Add(t5);


Aspose.Tasks.Task t6 = new Aspose.Tasks.Task();
t6.Name = “SummaryTask45”;
t6.Start = new DateTime(2014, 10, 9);
t6.Duration = new TimeSpan(80, 0, 0);
t6.OutlineLevel = 2;
t6.ConstraintType = ConstraintType.StartNoEarlierThan;
t6.ConstraintDate = t6.Start;
t6.DurationFormat = TimeUnitType.Day;
t4.Children.Add(t6);

Aspose.Tasks.Task t7 = new Aspose.Tasks.Task();
t7.Name = “Task 4”;
t7.Start = new DateTime(2014, 10, 9);
t7.Duration = new TimeSpan(24, 0, 0);
t7.OutlineLevel = 2;
t7.ConstraintType = ConstraintType.StartNoEarlierThan;
t7.ConstraintDate = t6.Start;
t7.DurationFormat = TimeUnitType.Day;
t6.Children.Add(t7);

Aspose.Tasks.Task t8 = new Aspose.Tasks.Task();
t8.Name = “Task 5”;
t8.Start = new DateTime(2014, 10, 15);
t8.Duration = new TimeSpan(48, 0, 0);
t8.OutlineLevel = 3;
t8.ConstraintType = ConstraintType.StartNoEarlierThan;
t8.ConstraintDate = t8.Start;
t8.DurationFormat = TimeUnitType.Day;
t6.Children.Add(t8);

Aspose.Tasks.Task t9 = new Aspose.Tasks.Task();
t9.Name = “Task 6”;
t9.Start = new DateTime(2014, 10, 21);
t9.Duration = new TimeSpan(16, 0, 0);
t9.OutlineLevel = 4;
t9.ConstraintType = ConstraintType.StartNoEarlierThan;
t9.ConstraintDate = t9.Start;
t9.DurationFormat = TimeUnitType.Day;
t8.Children.Add(t9);


Aspose.Tasks.Task t10 = new Aspose.Tasks.Task();
t10.Name = “Task 7”;
t10.Start = new DateTime(2014, 10, 14);
t10.Duration = new TimeSpan(32, 0, 0);
t10.OutlineLevel = 1;
t10.ConstraintType = ConstraintType.StartNoEarlierThan;
t10.ConstraintDate = t10.Start;
t10.DurationFormat = TimeUnitType.Day;
prj.RootTask.Children.Add(t10);


Aspose.Tasks.Task t11 = new Aspose.Tasks.Task();
t11.Name = “Task 8”;
t11.Start = new DateTime(2014, 10, 27);
t11.Duration = new TimeSpan(16, 0, 0);
t11.OutlineLevel = 1;
t11.ConstraintType = ConstraintType.StartNoEarlierThan;
t11.ConstraintDate = t11.Start;
t11.DurationFormat = TimeUnitType.Day;
prj.RootTask.Children.Add(t11);


Aspose.Tasks.Task t12 = new Aspose.Tasks.Task();
t12.Name = “Task 8”;
t12.Start = new DateTime(2014, 10, 13);
t12.Duration = new TimeSpan(24, 0, 0);
t12.OutlineLevel = 1;
t12.ConstraintType = ConstraintType.StartNoEarlierThan;
t12.ConstraintDate = t12.Start;
t12.DurationFormat = TimeUnitType.Day;
prj.RootTask.Children.Add(t12);


prj.CalcTaskUids();
prj.CalcTaskIds();
prj.UpdateReferences();
prj.Save(“Output2.xml”, SaveFileFormat.XML);
}