Expanding Tasks

Is there a way, prior to saving the MPP, to expand all the Tasks in the view. I have it saving to the ‘Task Usage’ view; however, I would like it expanded to see all the associate Task Assignments by default.

@cmlofal,

Can you elaborate the requiments in the form of snapshot and sample MPP file that you want to achieve using Aspose.Tasks API.

Attached is a zip containing an example of the MPP and format that I am required to provide.

Requirements:

  1. I am needing to create an MPP and save to the Task Usage view.
  2. The Tasks need to be expanded so that the user can see the associated Resource Assignments for each Task.
  3. The Summary Task, level 0, needs to be visible.

NOTE: Is the Summary Task and Root Task the same? Is there a way to change the name or text for the Summary Task.

// Displays the Summary Task
project.DisplayOptions.ShowProjectSummaryTask = true;
// Change the name? Doesn’t work.
project.RootTask.Set(Tsk.Name, “Jacobs Proprietary Content - DO NOT SHARE!”);

Thanks for the help!
Craig

Example.zip (3.7 MB)

@cmlofal,

Yes, its the same and the sample code that you have shared is correct. Can you please share which version you are using on your end.

I will share the feedback with you concerning this as soon as possible after duscussion.

@cmlofal,

The root task is a special task and it’s name equals to Project’s title (the same behavior can be seen in MS Project).

   project.Set(Prj.Title, "New root task name"); 

Please try using following sample code on your end.

  public void Do()
        {
            Project project = new Project("sample.mpp");
            TaskUtils.Apply(project.RootTask, new ExpandAllTasksAlgorithm(), 0);

            PdfSaveOptions saveOptions = new PdfSaveOptions()
            {
                PresentationFormat = PresentationFormat.TaskUsage,
                StartDate = project.Get(Prj.StartDate),
                EndDate = project.Get(Prj.FinishDate)
            };
            
            project.Save("output.pdf", saveOptions);
        }

        public class ExpandAllTasksAlgorithm : ITreeAlgorithm<Task>
        {
            public void PreAlg(Task el, int level)  {  }

            public void Alg(Task el, int level)
            {
                el.Set(Tsk.IsExpanded, true);
            }

            public void PostAlg(Task el, int level) {  }
        }

We are using ASPOSE 20.5.

Thanks for the suggestions. I will look into that today.

As for the Summary Task. Is there a way to set the text on that. If not, I might be able to handle that through template implementation. However, that’s a bit more that what I was interested in having to do just to name a Task value.

Thanks again.
Craig

These latest changes have gotten me much closer. :slight_smile: - see the attached example.
Example.zip (3.7 MB)

However, is there as way to expand the Task Assignments?

Essentially, the requirement is to create a Project report that displays the cost for each Task Item and it’s associated resources so that the user can modify cost and see the desired rollup throughout the report. Therefore, treating the report as a forecasting tool for estimation \ cost projection.

Is there a way to do the following, or something similar?

foreach (ResourceAssignment ra in task.Assignments)
{
ra.Set(Asn.IsExpanded, true);
}

I have share the code sample for expanding tasks for your convenience. Didn’t it work for you.

Yes, sir. See the latest attached example that I sent 6/9 Aug 15.

It is labeling the Summary Task \ Title and displaying the Tasks expanded. It is working for everything except displaying the Task Assignments. Is there a way to expand the Task Assignments?

Thanks.
Craig

The following code has been shared with you for expanding tasks. Please try using following sample code on your end.

  public void Do()
        {
            Project project = new Project("sample.mpp");
            TaskUtils.Apply(project.RootTask, new ExpandAllTasksAlgorithm(), 0);

            PdfSaveOptions saveOptions = new PdfSaveOptions()
            {
                PresentationFormat = PresentationFormat.TaskUsage,
                StartDate = project.Get(Prj.StartDate),
                EndDate = project.Get(Prj.FinishDate)
            };
            
            project.Save("output.pdf", saveOptions);
        }

        public class ExpandAllTasksAlgorithm : ITreeAlgorithm<Task>
        {
            public void PreAlg(Task el, int level)  {  }

            public void Alg(Task el, int level)
            {
                el.Set(Tsk.IsExpanded, true);
            }

            public void PostAlg(Task el, int level) {  }
        }

I still got the same results. All the Tasks are expanded to the Child task level. However, the Child tasks are not expanded. So, they don’t reveal the Task Assignment Resources. I would think that those should be expanded too since the logic is implemented to set IsExpanded to true for ALL tasks.

Example.zip (3.7 MB)

I tried your code and the following:

        ChildTasksCollector collector = new ChildTasksCollector();

        // Collect all the tasks from RootTask using TaskUtils
        TaskUtils.Apply(project.RootTask, collector, 0);

        // Set the collected Tasks IsExpanded true.
        foreach (Aspose.Tasks.Task task in collector.Tasks)
        {
            task.Set(Tsk.IsExpanded, true);
        }

Both returned the same results.

@cmlofal

Please check the attached image of your MPP file that I have opened in MS Project 2019 on my end. All tasks are appearing expanded to me. Can you please highlight the issue? What is that you require and is not expanded. Please share the desired MPP image that you want to achieve.

image.png (74.5 KB)

Thanks for the attached image. Appears to be working for you and not fully for me.
I am using 0365 to view he mpp. Could that be a difference?

Everything appears to expand but the assignments.

Example.zip (3.7 MB)

Does the Example that I sent open in Project 2019 as expected?
If so, then it very well may be a 0365 thing. Sadly I am unable to validate since I only have 0365.

I will say that my requirement is that I have to save to an MPP instead of PDF because the user needs to be able to use the report in an active way - more as a tool instead of a static report. Because of this I am NOT able to use the following save methods.

        PdfSaveOptions saveOptions = new PdfSaveOptions()
        {
            PresentationFormat = PresentationFormat.TaskUsage,
            StartDate = project.Get(Prj.StartDate),
            EndDate = project.Get(Prj.FinishDate)
        };
        
        project.Save("output.pdf", saveOptions);

Why does PdfSaveOptions have different parameters than MPPSaveOptions? I am unable to do there what PDF allows. This too, could be a difference in that I am unable to set the Start and EndDate values since MPP save doesn’t allow. I have to save to MPP instead of PDF to meet the requirement.

What does setting the Start and End on the PDF address since that is in the Project parameters? Is that something specific to PDF save?

Thanks for all your help!
Craig

@cmlofal,

There is no issue in tasks expansion on my end for this file too.

image.png (75.0 KB)

I am sorry, I didn’t get you properly here. Can you please elaborate and also provide a working sample along with source file that you want us to verify in same post so that things are not mixed up. Please share the requirements and new issue you are facing.

The following Example is the result of my latest implementation.
Example.zip (3.7 MB)

Below are the requirements:

  1. Must save to an mpp format.
  2. Must display the Summary Task (line 0).
  3. Must default the the Task Usage view.
  4. Must have all Tasks expanded.

All requirements are met except 4. As you can see in the example it’s not expanding the child Tasks in order to display the Assignments.

I am using the following code to expand the Task nodes, set the Task Usage, and name the Tasks.

    private void PersonalizePM03b(Aspose.Tasks.Project project)
    {
        #region Set the Default View to Task Usage

        foreach (var view in project.Views)
        {
            if (view.Screen.ToString().Contains("TaskUsage"))
            {
                project.DefaultView = view;
                break;
            }
        }

        #endregion  Set the Default View to Task Usage
        #region Set the Tasks IsExpanded to true

        ChildTasksCollector collector = new ChildTasksCollector();

        // Collect all the tasks from RootTask using TaskUtils
        TaskUtils.Apply(project.RootTask, collector, 0);

        // Set the collected Tasks IsExpanded true.
        foreach (Aspose.Tasks.Task task in collector.Tasks)
        {
            task.Set(Tsk.IsExpanded, true);
        }

        #endregion  Set the Tasks IsExpanded to true
        #region Rename Tasks

        project.DisplayOptions.ShowProjectSummaryTask = true;
        project.Set(Prj.ShowProjectSummaryTask, true);
        // Rename the parent task.
        project.Set(Prj.Title, "Jacobs Proprietary Content - DO NOT SHARE!");

        // Assign the initial Line 1 tasks to Line 1 as children making them Line 2 tasks.
        foreach (Aspose.Tasks.Task initialLine1Task in project.RootTask.Children)
        {
            string currentTaskName = initialLine1Task.Get(Tsk.Name);
            string newTaskName = m_TaskInfoDataTable.Rows[0]["NewFileName"].ToString().Split('_')[0];
            initialLine1Task.Set(Tsk.Name, string.Format("PM-03b_{0} - {1}", newTaskName, currentTaskName));
            break;
        }

        #endregion
    }

I am using the following code to save the file in an MPP format.
MemoryStream memoryStream = new MemoryStream();
Project.Save(memoryStream, Aspose.Tasks.Saving.SaveFileFormat.MPP);

@cmlofal

Please provide the snapshot view of the shared file where tasks are not getting expanded on your end. Please also provide the complete version of MS Project too that is having issue on your end.