How to complete a created task

Last post 01-10-2012, 8:11 AM by aspose.notifier. 15 replies.
Page 1 of 2 (16 items)   1 2 Next >
Sort Posts: Previous Next
  •  12-14-2010, 10:58 AM 273851

    How to complete a created task

    Hi there,

    I've created a plan containing tasks with a variety of durations, all allocated to a variety of resources.

    How do I set a task I've created to be completed? I've tried setting the task.percentcomplete to 100, but this doesn't seem to make any difference to the task on the generated plan.

    Could you please let me know what I should be doing?

    Many thanks,

    Steve

     

     

     
  •  12-15-2010, 6:48 AM 273983 in reply to 273851

    Re: How to complete a created task

    Hi there (again)

    Another (related) question please...

    The tasks that I flag as completed also need to have an 'actual' start and end date set. I've tried using 'actual' or 'manual' start and finish, but it just leaves a task of duration 0, finishing on 1 Jan 2011.

    Again, any help would be much appreciated :)

    Cheers,

    Steve

     

     
  •  12-15-2010, 7:37 AM 273990 in reply to 273983

    Re: How to complete a created task

    Attachment: Present (inaccessible)
    Hi Steve,

    In my case the code below works:

    using System;

    using Aspose.Tasks;

     

    namespace TestCompleteTask

    {

        class Program

        {

            static void Main(string[] args)

            {

                License license = new License();

                license.SetLicense("Aspose.Tasks.lic");

     

                ProjectReader reader = new ProjectReader();

                Project project = reader.Read("Project1.xml");

     

                Task task = project.GetTaskByUid(1);

                task.PercentComplete = 100;

                task.ActualStart = task.Start;

                task.ActualFinish = task.Finish;

                task.ActualDuration = task.Duration;

                task.ActualWork = task.Work;

                task.ActualCost = task.Cost;

     

                ProjectWriter writer = new ProjectWriter();

                writer.Write(project, "Project2.xml", TasksDataFormat.XML);

            }

        }

    }

    In case your task has children they have to be completed too.
    See test data and screen shot attached.

    Sergey Polshkov
    Team Leader, Aspose.Tasks & Aspose.Diagram Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  12-15-2010, 10:47 AM 274053 in reply to 273990

    Re: How to complete a created task

    Hi,

    Thanks for the response. Unfortunately, I still can't add a completed task.

    The code I use:

    Dim oTask As New Task

    oTask.Type = TaskType.FixedUnits

    If (oRow.Item("TaskIsCompleted") & "") = "True" Then

       oTask.PercentComplete = 100

       oTask.ActualStart =dtStartTime

       oTask.ActualFinish = dtEndTime

       oTask.ActualDuration = New TimeSpan(lEffortInHours, 0, 0)

    Else

       oTask.Duration = New TimeSpan(lEffortInHours, 0, 0)

       oTask.DurationFormat = TimeUnitType.Day

       oTask.RemainingDuration = New TimeSpan(lEffortInHours, 0, 0)

       oTask.Deadline = dtCompletionDate

       oTask.ConstraintDate = dtCompletionDate

       oTask.ConstraintType = ConstraintType.MustFinishOn

    End If

    This works fine for non-completed jobs, but creates 0 duration tasks at 31st Dec 2010 for completed jobs.

    Any advice would be much appreciated,

    Cheers,

    Steve

     

     

     

     
  •  12-16-2010, 1:44 AM 274138 in reply to 274053

    Re: How to complete a created task

    Hi Steve,

    I have used the code below to create a completed new task to the project from my previous post:

    using System;

    using Aspose.Tasks;

     

    namespace TestCompleteTask

    {

        class Program

        {

            static void Main(string[] args)

            {

                License license = new License();

                license.SetLicense("Aspose.Tasks.lic");

     

                ProjectReader reader = new ProjectReader();

                Project project = reader.Read("Project1.xml");

                Calendar cal = project.Calendar;

     

                //Create a new completed task.

                Task task = new Task("New completed task.");

                task.Uid = project.NextTaskUid;

                task.Type = TaskType.FixedUnits;

                task.Start = new DateTime(2010, 12, 15, 8, 0, 0);

                task.Duration = new TimeSpan(80, 0, 0);

                task.Finish = project.Calendar.GetFinishDateByStartAndWork(task.Start, task.Duration);

                task.DurationFormat = TimeUnitType.Day;

     

                task.ActualStart = task.Start;

                task.ActualFinish = task.Finish;

                task.ActualDuration = task.Duration;

                task.PercentComplete = 100;

     

                //Have to add an empty resource assignments to the task to make it completed.

                ResourceAssignment ra = new ResourceAssignment();

                ra.Uid = project.NextResourceAssignmentUid;

                ra.Task = task;

                ra.Start = task.Start;

                ra.Finish = task.Finish;

                ra.TimephasedDataFromTaskDuration(cal);

                project.ResourceAssignments.Add(ra);

     

                //Complete old task.

                Task old_task = project.GetTaskByUid(1);

                old_task.PercentComplete = 100;

                old_task.ActualStart = task.Start;

                old_task.ActualFinish = task.Finish;

                old_task.ActualDuration = task.Duration;

     

                project.RootTask.Children.Add(task);

                project.CalcTaskIds();

                project.CalcResourceAssignmentIds();

               

                ProjectWriter writer = new ProjectWriter();

                writer.Write(project, "Project2.xml", TasksDataFormat.XML);

            }

        }

    }


    Now both tasks are shown as completed in MS Project 2003/2007/2010.

    I have created a new issue "Add a method to change task progress." with ID = 22450 and linked it to this forum thread. We are going to add a new method to change task's progress automatically.

    Sorry for the inconvenience.

    Sergey Polshkov
    Team Leader, Aspose.Tasks & Aspose.Diagram Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  12-20-2010, 7:44 AM 274635 in reply to 274138

    Re: How to complete a created task

    Sergey,

    Hi, thanks for that.

    I can now get new tasks completed with empty resource allocations. My remaining problem is that we still need to allocate existing resources to these tasks- but as soon as I try allocating them, the tasks become incomplete.

    Could you amend the code you wrote above for me so that it had an actual resource allocated to the task?

    Thanks,

    Steve

     

     

     
  •  12-20-2010, 9:25 AM 274647 in reply to 274635

    Re: How to complete a created task

    Hi Steve,

    Try to use the code below:

    using System;

    using Aspose.Tasks;

     

    namespace TestCompleteTask

    {

        class Program

        {

            static void Main(string[] args)

            {

                License license = new License();

                license.SetLicense("Aspose.Tasks.lic");

     

                ProjectReader reader = new ProjectReader();

                Project project = reader.Read("Project1.xml");

                Calendar cal = project.Calendar;

     

                //Create a new completed task.

                Task task = new Task("New completed task.");

                task.Uid = project.NextTaskUid;

                task.Type = TaskType.FixedUnits;

                task.Start = new DateTime(2010, 12, 15, 8, 0, 0);

                task.Duration = new TimeSpan(80, 0, 0);

                task.Finish = cal.GetFinishDateByStartAndWork(task.Start, task.Duration);

                task.DurationFormat = TimeUnitType.Day;

     

                task.ActualStart = task.Start;

                task.ActualFinish = task.Finish;

                task.ActualDuration = task.Duration;

                task.PercentComplete = 100;

     

                //Create a new resource.

                Resource resource = new Resource();

                resource.Name = "Employee";

                resource.Type = ResourceType.Work;

                resource.Work = task.Duration;

                resource.ActualWork = resource.Work;

                resource.Uid = project.NextResourceUid;

                project.Resources.Add(resource);

     

                //Create a resource assignment

                ResourceAssignment ra = new ResourceAssignment();

                ra.Uid = project.NextResourceAssignmentUid;

                ra.Task = task;

                ra.Resource = resource;

                ra.ActualWork = ra.Work = resource.Work;

                ra.Start = task.Start;

                ra.Finish = task.Finish;

                ra.Units = 1;

                ra.TimephasedDataFromTaskDuration(cal);

                project.ResourceAssignments.Add(ra);

     

                project.RootTask.Children.Add(task);

                project.CalcTaskIds();

                project.CalcResourceIds();

                project.CalcResourceAssignmentIds();

                

                ProjectWriter writer = new ProjectWriter();

                writer.Write(project, "Project2.xml", TasksDataFormat.XML);

            }

        }

    }


    It works OK with me.

    Sergey Polshkov
    Team Leader, Aspose.Tasks & Aspose.Diagram Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  12-21-2010, 8:02 AM 274869 in reply to 274647

    Re: How to complete a created task

    Hi Sergey,

    I tried using your code, and I can now get it almost working!

    The remaining problem is that all tasks that I need to set as complete are only set to 99% complete. If I set it to 100% by hand in MS Project, it then completes OK.

    Is this an issue that you have seen before?

    Cheers,

    Steve

     

     
  •  12-21-2010, 8:07 AM 274870 in reply to 274869

    Re: How to complete a created task

    I tried to go back to the bare basics, and get your code to work.

    I tried to amend it so that it would create a project from scratch, but couldn't get the following code to work. Any help would be appreciated (again!). Cheers, Steve

            Dim license3 As Aspose.Tasks.License = New Aspose.Tasks.License
            license3.SetLicense(HttpContext.Current.Server.MapPath("Aspose.Tasks.lic"))

            Dim oProject As New Project
            oProject.WorkFormat = TimeUnitType.Hour
            oProject.MinutesPerDay = 60 * 8

            Dim cal As Aspose.Tasks.Calendar = New Aspose.Tasks.Calendar()
            cal.Name = "Calendar24x7"
            Aspose.Tasks.Calendar.MakeStandardCalendar(cal)

            'add working days monday through thursday with default timings       
            cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Monday))
            cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Tuesday))
            cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Wednesday))
            cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Thursday))
            cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Friday))
            cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Saturday))
            cal.Days.Add(WeekDay.CreateDefaultWorkingDay(DayType.Sunday))

            oProject.Calendars.Add(cal)
            oProject.CalcCalendarUids()

            Dim Task As New Task("New completed task.")
            Task.Calendar = cal
            Task.Uid = oProject.NextTaskUid
            Task.Type = TaskType.FixedUnits
            Task.Start = New DateTime(2010, 12, 15, 8, 0, 0)
            Task.Duration = New TimeSpan(80, 0, 0)
            Task.Finish = cal.GetFinishDateByStartAndWork(Task.Start, Task.Duration)
            Task.DurationFormat = TimeUnitType.Day

            Task.ActualStart = Task.Start
            Task.ActualFinish = Task.Finish
            Task.ActualDuration = Task.Duration
            Task.PercentComplete = 100

            Dim Resource As New Resource()
            Resource.Name = "Employee"
            Resource.Type = ResourceType.Work
            Resource.Work = Task.Duration
            Resource.ActualWork = Resource.Work
            Resource.Uid = oProject.NextResourceUid
            oProject.Resources.Add(Resource)

            Dim ra As New ResourceAssignment()
            ra.Uid = oProject.NextResourceAssignmentUid
            ra.Task = Task
            ra.Resource = Resource
            ra.ActualWork = Resource.Work
            ra.Work = Resource.Work
            ra.Start = Task.Start
            ra.Finish = Task.Finish
            ra.Units = 1
            ra.TimephasedDataFromTaskDuration(cal)
            oProject.ResourceAssignments.Add(ra)

            oProject.RootTask.Children.Add(Task)

            oProject.CalcTaskIds()
            oProject.CalcResourceIds()
            oProject.CalcResourceAssignmentIds()

            Dim prjWriter As New ProjectWriter()

            Me.Response.ContentType = "application/vnd.ms-project"
            Me.Response.AppendHeader("Content-Disposition", "attachment; filename=project.xml")
            Me.Response.Flush()
            Dim st As System.IO.Stream = Me.Response.OutputStream
            prjWriter.Write(oProject, st, TasksDataFormat.XML)
            Me.Response.End()

     
  •  12-21-2010, 8:28 AM 274875 in reply to 274870

    Re: How to complete a created task .NET

    Hi,

    I have seen the 99% problem before and have not had time to track down the problem.  I appreciate your taking the time to do this!!!!!

    I also did not realise that an assignment was necessary to mark a task as complete. 

    MS Project VBA is very helpful when setting completion dates or % completes... I believe there is a lot of data integrity checks that are made when certain actions are taken to keep everything consistent.

    Many thanks for digging into this area!!!

    Regards, Bruce

     
  •  12-21-2010, 8:48 AM 274879 in reply to 274875

    Re: How to complete a created task

    Hi All,

    I have tested the code above with MS Project 2003/2007/2010 and the tasks are shown as 100% completed. Could you share your code and data samples to check the issue on our side?

    Any information is highly appreciated! Thank you for your cooperation!

    The empty assignment is not always necessary, but MS Project creates it for each new task (to track the task duration, work and splits) so I just followed it. In case if the task was created in MS Project the file contains the assignment.

    I am going to create a sample for Steve's case, but I would recommend to create a template and read it in XML format instead of creation in run time.

    Sergey Polshkov
    Team Leader, Aspose.Tasks & Aspose.Diagram Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  12-21-2010, 8:53 AM 274882 in reply to 274879

    Re: How to complete a created task

    Sergey, Hi,

    So the code I included above creates a project plan OK?

    Meanwhile, I'll try reading in an empty mpp file first...

     

    Cheers,

    Steve

     

     
  •  12-21-2010, 9:07 AM 274887 in reply to 274882

    Re: How to complete a created task

    Hi Steve,

    I have not tested your code yet, I just wrote about the 99% problem which I have not seen before...
    Sorry for the misleading.

    Sergey Polshkov
    Team Leader, Aspose.Tasks & Aspose.Diagram Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
  •  12-21-2010, 9:07 AM 274888 in reply to 274882

    Re: How to complete a created task

    Hi,

    I can now get a task generated from the following code, but the task is not completed. It may be due to me translating the c# line containing two ='s incorrectly...

     

     

        Private Sub Test()

            '    Try
            Dim license3 As Aspose.Tasks.License = New Aspose.Tasks.License
            license3.SetLicense(HttpContext.Current.Server.MapPath("Aspose.Tasks.lic"))

            Dim oRdr As New ProjectReader()
            Dim oProject As Project = oRdr.Read(HttpContext.Current.Server.MapPath("~/ReportTemplates/Empty Template.mpp"))


            '  Dim oProject As New Project
            oProject.WorkFormat = TimeUnitType.Hour
            oProject.MinutesPerDay = 60 * 8

            Dim cal As Aspose.Tasks.Calendar = oProject.Calendar ' New Aspose.Tasks.Calendar()
           
            Dim Task As New Task("New completed task.")
            Task.Calendar = cal
            Task.Uid = oProject.NextTaskUid
            Task.Type = TaskType.FixedUnits
            Task.Start = New DateTime(2010, 12, 15, 8, 0, 0)
            Task.Duration = New TimeSpan(80, 0, 0)
            Task.Finish = cal.GetFinishDateByStartAndWork(Task.Start, Task.Duration)
            Task.DurationFormat = TimeUnitType.Day

            Task.ActualStart = Task.Start
            Task.ActualFinish = Task.Finish
            Task.ActualDuration = Task.Duration
            Task.PercentComplete = 100

            Dim Resource As New Resource()
            Resource.Name = "Employee"
            Resource.Type = ResourceType.Work
            Resource.Work = Task.Duration
            Resource.ActualWork = Resource.Work
            Resource.Uid = oProject.NextResourceUid
            oProject.Resources.Add(Resource)

            Dim ra As New ResourceAssignment()
            ra.Uid = oProject.NextResourceAssignmentUid
            ra.Task = Task
            ra.Resource = Resource
            ra.ActualWork = Resource.Work
            ra.Work = Resource.Work
            ra.Start = Task.Start
            ra.Finish = Task.Finish
            ra.Units = 1
            ra.TimephasedDataFromTaskDuration(cal)
            oProject.ResourceAssignments.Add(ra)

            oProject.RootTask.Children.Add(Task)

            oProject.CalcTaskIds()
            oProject.CalcResourceIds()
            oProject.CalcResourceAssignmentIds()

            Dim prjWriter As New ProjectWriter()

            Me.Response.ContentType = "application/vnd.ms-project"
            Me.Response.AppendHeader("Content-Disposition", "attachment; filename=project.xml")
            Me.Response.Flush()
            Dim st As System.IO.Stream = Me.Response.OutputStream
            prjWriter.Write(oProject, st, TasksDataFormat.XML)
            Me.Response.End()

        End Sub

     
  •  12-21-2010, 11:56 AM 274906 in reply to 274888

    Re: How to complete a created task

    Hi Steve,

    See below a sample when a project was created from scratch:

    using System;

    using Aspose.Tasks;

     

    namespace TestCompleteTask

    {

        class Program

        {

            static void Main(string[] args)

            {

                License license = new License();

                license.SetLicense("Aspose.Tasks.lic");

     

                Project project = new Project();

                project.StartDate = new DateTime(2010, 12, 15, 8, 0, 0);

                project.FinishDate = new DateTime(2011, 12, 31, 17, 0, 0);

                project.MinutesPerDay = 8 * 60;

                project.MinutesPerWeek = 5 * 8 * 60;

                project.DaysPerMonth = 20;

                project.DefaultStartTime = new DateTime(1, 1, 1, 8, 0, 0);

                project.DefaultFinishTime = new DateTime(1, 1, 2, 17, 0, 0);

                project.DurationFormat = TimeUnitType.Hour;

                project.WorkFormat = TimeUnitType.Hour;

                Calendar standard = new Calendar("Standard");

                standard = Calendar.MakeStandardCalendar(standard);

                project.Calendars.Add(standard);

                project.Calendar = standard;

     

                Calendar employeeCalendar = new Calendar("Employee");

                employeeCalendar.BaseCalendar = standard;

                project.Calendars.Add(employeeCalendar);

     

                //Create root task.

                Task root = new Task();

                root.Uid = project.NextTaskUid;

                root.Type = TaskType.FixedUnits;

                project.RootTask = root;

     

                //Create a new completed task.

                Task task = new Task("New completed task.");

                task.Uid = project.NextTaskUid;

                task.Type = TaskType.FixedUnits;

                task.Start = new DateTime(2010, 12, 15, 8, 0, 0);

                task.Duration = new TimeSpan(80, 0, 0);

                task.Finish = standard.GetFinishDateByStartAndWork(task.Start, task.Duration);

                task.DurationFormat = TimeUnitType.Day;

                task.Work = task.Duration;

                task.RegularWork = task.Work;          

              

                task.ActualStart = task.Start;

                task.ActualFinish = task.Finish;

                task.ActualDuration = task.Duration;

                task.ActualWork = task.Work;

                task.PercentComplete = 100;

     

                project.RootTask.Children.Add(task);

     

                //Create a root resource.

                Resource res = new Resource();

                res.Uid = project.NextResourceUid;

                project.Resources.Add(res);

     

                //Create a new resource.

                Resource resource = new Resource();

                resource.Name = "Employee";

                resource.Type = ResourceType.Work;

                resource.Work = task.Duration;

                resource.RegularWork = resource.Work;

                resource.ActualWork = resource.Work;

                resource.Uid = project.NextResourceUid;

                resource.Calendar = employeeCalendar;

                project.Resources.Add(resource);

     

                //Create a resource assignment.

                ResourceAssignment ra = new ResourceAssignment();

                ra.Uid = project.NextResourceAssignmentUid;

                ra.Task = task;

                ra.Resource = resource;

                ra.ActualWork = resource.Work;

                ra.Work = resource.Work;

                ra.RegularWork = resource.Work;

                ra.Start = task.Start;

                ra.Finish = task.Finish;

                ra.ActualStart = ra.Start;

                ra.ActualFinish = ra.Finish;

                ra.Units = 1;

                project.ResourceAssignments.Add(ra);

     

                project.CalcCalendarUids();

                project.CalcTaskIds();

                project.CalcResourceIds();

                project.CalcResourceAssignmentIds();

               

                ProjectWriter writer = new ProjectWriter();

                writer.Write(project, "Project3.xml", TasksDataFormat.XML);

            }

        }

    }


    Again I can see the task as 100% completed in MS Project (2007).

    Sergey Polshkov
    Team Leader, Aspose.Tasks & Aspose.Diagram Team
    http://www.aspose.com
    Your File Format Experts
    Keep in touch! We're on Twitter and Facebook
     
Page 1 of 2 (16 items)   1 2 Next >
View as RSS news feed in XML