Search code examples
c#ms-project-server-2013psi

How to determine resource work availability in PSI


I am using PSI interface of MS Project Server 2013 via Microsoft.SharePoint.Client context.

I need to get number or hours available for specific resource in specific date.

For example, Resource1 has current max units 100%. I set 8h work day, and it means that Resource1 has 8h every work day. I set Resource1 plan work 2h to today. So I need to get max avaliable hours for today: 8h - 2h = 6h.

//open project context
ProjectContext projContext;
projContext = new ProjectContext(pwaPath);

//load enterprise resource
projContext.Load(projContext.EnterpriseResources);
projContext.ExecuteQuery();

//get first resource
EnterpriseResource resource = projContext.EnterpriseResources[0];

//what should I do next?

Does exist any way to get this estimate without manual calculations?


Solution

  •         DateTime dtStart = DateTime.Parse("09.04.2015");
            DateTime dtEnd = DateTime.Parse("12.28.2016");
            var plan = checkoutProj.GetResourcePlan(dtStart, dtEnd, TimeScale.Days);
    
            projContext.Load(plan.Assignments);
            projContext.ExecuteQuery();
    
            DateTime dttest = DateTime.Parse("8.28.2016");
            var assgn = plan.Assignments[0].Intervals.GetByStart(dttest);
    
            projContext.Load(plan.Assignments[0].Intervals);
            projContext.Load(plan.Assignments[1].Intervals);
            projContext.Load(assgn);
            projContext.ExecuteQuery();
    

    assgn.Duration gives you workload for specific day.