0

How to import the employee's work hours to TimeScaleData in microsoft project file using vsto add-in?

Here is the sample data I have,

[{Name:"Phase 1", BaselineStart:"2023-01-01", BaselineFinish:"2023-03-30",
                Employees:[
                {Name:"John",EntryDates:[{DateEntered:"2023-12-01",Hours:6},{DateEntered:"2023-12-02",Hours:8},{DateEntered:"2023-12-05",Hours:9}]},
                {Name:"Rosy",EntryDates:[{DateEntered:"2023-11-04",Hours:2},{DateEntered:"2023-12-02",Hours:8},{DateEntered:"2023-10-16",Hours:9}]}
                ]
            }]

Here is my code, but it giving me an error like System.Runtime.InteropServices.COMException: 'The argument value is not valid.' at this line Assignment newAssignment = newPhaseTask.Assignments.Add(resource);

Project project = Globals.ThisAddIn.Application.ActiveProject;
Task newPhaseTask = project.Tasks.Add(phase.Name);
foreach (Employee emp in Employees)
{ 
 Resource resource = null;
 foreach (Resource projResource in project.Resources)
 {
     if (projResource.Name.Equals(emp.Name, StringComparison.OrdinalIgnoreCase))
     {
         resource = projResource;
         break;
     }
 }
 if (resource == null)
 {
     resource = project.Resources.Add(emp.Name);
 }
foreach (var date in emp.EntryDates)
{
 foreach (Assignment assignment in newPhaseTask.Assignments)
 {
     if (assignment.Resource == resource)
     {
         assignmentExists = true;
         break; // Exit the loop if an assignment for the resource is found
     }
 }
 if (!assignmentExists)
 {
     // Create a new assignment for the resource on the task
     Assignment newAssignment = newPhaseTask.Assignments.Add(resource);

     // Assign work hours to the specified date using TimeScaleData
     newAssignment.TimeScaleData(date.DateEntered, date.DateEntered, PjAssignmentTimescaledData.pjAssignmentTimescaledWork, PjTimescaleUnit.pjTimescaleDays, 1).Add(date.DateEntered, date.Hours);
 }
}
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.