Preview leveling#
Show the user what leveling would change before it touches the project, then keep the leveled plan or throw it away.
Project#level commits. It writes levelingDelay and pauses into the project and accepts the leveled dates as the new baseline. To get a proposal instead, level a copy. Project#copy is cheap, because the data stays shared until one copy is edited.
Prerequisites#
- A solved
Project:solve(data, options)has run. - The data has
resourcesandassignments, so there's overallocation to level. - The project is forward-scheduled.
levelrefusesconfig.scheduleFromEnd = truewith anInputException.
Steps#
-
Copy the solved project:
Project draft ; -
Level the copy. The original keeps its dates, its baseline and its overallocation:
LevelingResult proposal ; -
Show the proposal.
proposal.schedule.updateslists the tasks leveling moved, with their new dates,levelingDelayandpauses. The diff is relative to the state the call started from, and that state matches the original. Apply the entries to the model you already hold.for -
Show what leveling couldn't fix.
proposal.schedule.overallocationsholds the windows left after leveling. It'snullwhen the project has no assignments. Each window has areason, such asfixed-taskorpriority-1000:if -
Apply the user's choice:
- Accept: replace the original with the copy,
project = draft;. The project now holds the leveled baseline. - Reject: drop
draft. Nothing else needs undoing.
Replace the original only if nobody edited it after you copied it. Otherwise the proposal comes from an older state, so level a new copy.
- Accept: replace the original with the copy,
The full example levels two tasks that book the same developer full time on Monday and Tuesday:
;
;
Result#
The example prints the one task leveling moved. The proposal has no overallocation left. The original still has one:
B: 2026-08-12 08:00 .. 2026-08-14 08:00, delay 2.0
overallocated resources left: 0
original still overallocated: 1
baseline matches proposal: true
B waits two days for A, so its levelingDelay is 2.0. Until you replace project with draft, project still reports the Monday-Tuesday window on dev1. After the swap, baselineId is the token from the leveling result. Baseline tokens are opaque, so compare them only within one process.
The copy is a full solved project, so you can also call draft.loadProfile(...) on it to draw the leveled load. See Resource load. To compare leveling across several alternative change sets with scores, use evaluate with EvaluateOptions.level. See Evaluating alternatives. For options, reasons and splits, see Leveling resources.