Percent of Complete is always 99%

I Have method which set default values of Task

private void SetTaskDefaultValue(Task rootTask, PointDto point, Task newTask, bool isTechTask)
{
newTask.Set(Tsk.Uid, point.Id);
newTask.Set(Tsk.Type, TaskType.FixedDuration);

        if (point.IsMilestone)
        {
            newTask.Set(Tsk.IsMilestone, true);
            newTask.Set(Tsk.Duration, rootTask.ParentProject.GetDuration(0));
        }
        else
        {
            if (point.Duration != null)
            {
                newTask.Set(Tsk.Duration, rootTask.ParentProject.GetDuration(point.Duration.Value));
                newTask.Set(Tsk.ActualDuration, rootTask.ParentProject.GetDuration(point.Duration.Value));
            }
        }           
        
        if (point.ProjectedStart != null)
        {
            newTask.Set(Tsk.Start, point.ProjectedStart.Value);
        }

        if (point.ProjectedEnd != null)
        {
            newTask.Set(Tsk.Finish, point.ProjectedEnd.Value);
        }

        if (point.ActualStart != null)
        {
            newTask.Set(Tsk.ActualStart, point.ActualStart.Value);
        }

        if (point.ActualEnd != null)
        {
            newTask.Set(Tsk.ActualFinish, point.ActualEnd.Value);
        }

        newTask.Baselines.Add(new TaskBaseline(rootTask)
        {
            Start = point.PlannedStart ?? default,
            Finish = point.PlannedEnd ?? default,
        });

        if (point.Completion != null)
        {
            newTask.Set(Tsk.PercentComplete, point.Completion.Value);
            newTask.Set(Tsk.PhysicalPercentComplete, point.Completion.Value);
            newTask.Set(Tsk.PercentWorkComplete, point.Completion.Value);
        }

        if (point.ConstraintType != null && !isTechTask)
        {
            newTask.Set(Tsk.ConstraintType, point.ConstraintType.Value);
        }
    }

`
My problem
I am setting percent to 100 but after saving file the percent of complete is changing to 99, but when I open same file in https://www.projectplan365.com/projectviewernow/tViews.aspx instead of microsoft project, everything is okay. My calculation mode is Manual because of perfomance.

@Vardan21 ,
unfortunately we cannot determine the cause of the problem using the given snippet.
The main interest is which exact values are set to task’s properties

Could you prepare a compilable and runnable example which we can use to reproduce and fix the issue?

Problem is that, when I debuging file all fileds are correct , which are will affect to Actual.Finish but when saving file and open in microsft project, Actual.Finish date dissapear and because of that there is always 99%, but the same file in Project Plan 365 show correct.

This is PointDto as a json

{
            "id": 752180,
            "wbs": "1",
            "name": "предпроект",
            "code": "1075-2180",
            "stage": "Предпроект",
            "workType": null,
            "manageObject": {
                "id": 423651,
                "name": "MOY",
                "code": "П"
            },
            "lineNumber": 1,
            "productionCalendarId": null,
            "projectedStart": "2023-04-18T09:00:00Z",
            "projectedEnd": "2023-04-21T18:00:00Z",
            "actualStart": "2023-04-18T09:00:00Z",
            "actualEnd": "2023-04-21T18:00:00Z",
            "plannedStart": "2023-04-01T09:00:00Z",
            "plannedEnd": "2023-04-06T18:00:00Z",
            "duration": 4.0,
            "responsible": "Громов Виктор Павлович",
            "responsibleId": 1,
            "roleResponsible": "Директор проекта",
            "completion": 100,
            "lifeCycleStages": "",
            "levelControl": null,
            "levelControlId": null,
            "ctLevelPresident": null,
            "ctLevelPresidentId": null,
            "parentId": null,
            "predecessors": [],
            "constraintType": 0,
            "constraintDate": null,
            "isMilestone": false,
            "additionalData": {}
}

@Vardan21,
We will try to investigate the issue using the pieces of information you’ve provided.

I find the solution. The solution is that I add temporary resource to task, because if task type is FixedDuration, it can not calculate complete percent without any resource.

@Vardan21,
thank you for the additional info.

@Vardan21,
regarding your initial question: you need to set default assignment’s properties in the following way:

var defaultAssignment = newTask.Assignments[0];
defaultAssignment.PercentWorkComplete = newTask.PercentWorkComplete;
defaultAssignment.Work = newTask.Duration;
defaultAssignment.ActualWork = newTask.ActualDuration;

Explanation:
For task without assigned resources MS Project creates “default” assignment (or assignment of system “Unassigned” resource) and uses its fields when displaying task’s properties.
Because you’re using CalculationMode.Manual, you also should set Work, ActualWork and PercentWorkComplete of the default assignment to make it consistent with task’s properties.

1 Like