Search code examples
c#csomproject-serverproject-online

Add resource assignment work by day


For a few days I'm trying to write the assignment progress for a specific task for a specific date. For example: I'm able to set the overall progress of the task but not the actual work that resource did at a given date. We are able to do that using Project Pro on the Task Usage view, but we need to automate some actions based on a file generated by another system and that's why i'm working in this solution but I could not find any object that would allow me to save the actual work value for a date. I'm using the CSOM library and Project Online.

This problem is driving me crazy! Any help would be very appreciated. Thanks in advance!

EDIT:

In case I wasn't clear enough, I basically need to get and set data from the resource assignments BY DAY, as we can view and set through the TASK USAGE screen on Project PRO, but I need to do it using CSOM and Project Online. Here's the view I'm talking about: Project Pro Task Usage view


Solution

  • At the end, we managed to find a way out... Here's how we did it:

        private void SaveAssignmentData(Guid id, DateTime start, DateTime finish, Config config)
        {  
    
            //start = DateTime.Today.AddHours(8);
            //finish = start.AddHours(10); //from 8am to 6pm
    
            var ctx = new Connection().ProjectOnline(config.SpOnlineSite, config.SpOnlineUsuario, config.SpOnlineSenha); //simple method to get the current context
    
            var resources = ctx.EnterpriseResources;
            ctx.Load(resources);
            ctx.ExecuteQuery();
            var resource = ctx.EnterpriseResources.FirstOrDefault(i => i.Email == "[email protected]");
            if (resource == null) throw new Exception("Resource not found.");
            ctx.Load(resource, p => p.Assignments);
            ctx.ExecuteQuery();
    
            var timePhase = resource.Assignments.GetTimePhase(start, finish);
            ctx.Load(timePhase, p => p.Assignments);
            ctx.ExecuteQuery();
    
            var statusAssignment = timePhase.Assignments.FirstOrDefault(i => i.Id == id);
            if (statusAssignment != null)
            {
                statusAssignment.ActualWork = "6h";
                statusAssignment.SubmitStatusUpdates("through csom");
                ctx.ExecuteQuery();
            }
        }