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 leveling_delay and pauses into the project and accepts the leveled dates as the new baseline. To get a proposal instead, level a copy made with project.clone().
clone() copies the whole project at once, so its cost grows with the project's size.
Prerequisites#
- A solved
Project:project.solve(data)has run. - The data has
resourcesandassignments, so there's overallocation to level. - The project is forward-scheduled.
levelrefusesconfig.schedule_from_end: truewith anInputError.
Steps#
-
Clone the solved project:
const = ; -
Level the clone. The original keeps its dates, its baseline and its overallocation:
const = ; -
Show the proposal.
proposal.updateslists the tasks leveling moved, with their new dates,leveling_delayandpauses. The diff is relative to the state the call started from. That state matches the original, so you can apply the entries to the model you already hold.NoteThe leveling result is a
ScheduleResultwith an addedroundsfield; readupdatesdirectly on it. -
Show what leveling couldn't fix.
proposal.overallocationsholds the windows left after leveling. Each window has areason, such asfixed-taskorpriority-1000:Notewindowsis absent, not an empty array, when a resource has no overallocated window. -
Apply the user's choice:
- Accept: replace the original with the clone,
project = draft;. The project now holds the leveled baseline. - Reject: drop
draft. Nothing else needs undoing.
Replace the original only if it hasn't been edited since you cloned it. Otherwise the proposal was computed from an older state, so level a new clone.
- Accept: replace the original with the clone,
The full example levels two tasks that book the same developer full time on Monday and Tuesday:
// Monday, August 10, 2026, on the default calendar.
const = ;
let = new;
;
const = ;
const = ;
const = proposal.?. ?? 0;
;
const = true;
const = ;
;
Result#
The example prints the one task leveling moved, and nothing is left overallocated:
B: 2026-08-12 08:00 .. 2026-08-14 08:00, delay 2
overallocated resources left: 0
baseline: leveled
B waits two days for A, so its leveling_delay is 2. Until you replace project with draft, project still reports the Monday-Tuesday window on dev1, and a solve(null) on it returns no updates. After the swap, baselineId is the token from the leveling result.
The clone 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 the level option instead. See Evaluating alternatives. For options, reasons and splits, see Leveling resources.