3

I want to extract the planned work over the time from MS Project using MPXJ. Does anyone know how to get these figures via API? I cannot find any appropriate method for doing this.

(Concrete scenario: I want to draw a chart with the planned work on the y-axis and the date on the x-axis)

Philipp
  • 383
  • 5
  • 20

2 Answers2

3

The answer Jon gave above was correct at the time, but as of version 4.2 of MPXJ, the api for dealing with timephased work (and cost) has been changed considerably. Here's what you would do now:

This part's the same:

TimescaleUtility timescale = new TimescaleUtility();
ArrayList<DateRange> dateList = timescale.createTimescale(startDate, TimescaleUnits.DAYS, length);

This has changed (notice the different return type and method for getting the planned work, and the new method on the TimephasedUtility class):

List<TimephasedWork> plannedWork = assignment.getTimephasedWork();

ProjectCalendar calendar = assignment.getCalendar();
TimephasedUtility util = new TimephasedUtility();
ArrayList<Duration> durationList = util.segmentWork(calendar, plannedWork, TimescaleUnits.DAYS, dateList);

One thing you also have to know is that the planned work data only contains values for work that has not been completed yet (ie, no actual values have been recorded for that time). For example, if your assignment lasts for 4 days, and you've completed 50% of the work, then you will have timephased ACTUAL work values for the first two days, and timephased PLANNED work values only for the last two days. They do not overlap or duplicate.

So if you are trying to show planned work values for the whole time period of the assignment (like what you'd see in the Task Usage views in MS Project), you'd need to also retrieve the timephased actual work values and use them as if they were planned work too.

patmortech
  • 10,139
  • 5
  • 38
  • 50
2

your starting point is the following methods on the assignment object:

List<TimephasedResourceAssignment> complete = assignment.getTimephasedComplete();
List<TimephasedResourceAssignment> planned= assignment.getTimephasedComplete();

As their names suggest, these will get you either the planned work or the complete work, expressed as work carried out over periods of time.

The "gotcha" here is that this data is represented in a compact format (reflecting how it's stored by MS Project internally), and this does not lend itself well to showing a period-by-period breakdown of work.

To get what you want, there are two utility classes which will help you to convert this compact representation into a list of work values. For example, you can give them a start date a period type (day, week, month and so on) and a number of periods, and ask for the work to be broken down over these periods.

First step is to create an instance of the TimescaleUtility class, and get it to generate a range of dates for you. You give it the start date, the timescale units you require, and the numnber of periods you want.

TimescaleUtility timescale = new TimescaleUtility();
ArrayList<DateRange> dateList = timescale.createTimescale(startDate, TimescaleUnits.DAYS, length);

The dateList variable now contains the list of date ranges you are going to split the work over. This split is carried out using the TimephasedUtility class:

ProjectCalendar calendar = assignment.getCalendar();
TimephasedUtility timephased = new TimephasedUtility();
ArrayList<Duration> durationList = timephased.segmentResourceAssignment(calendar, planned, TimescaleUnits.DAYS, dateList);

That's it, your durationList now contains one entry for each entry in the datList showing the amount of work for that period.

Hope that makes sense!

Jon

Jon Iles
  • 2,519
  • 1
  • 20
  • 30