Preview leveling#
Show the user what leveling would change before it touches the project, then keep the leveled plan or throw it away.
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 clone(). A clone is cheap because the data stays shared until one copy is edited. It's a separate handle in wasm memory, though, so free it like any other.
Prerequisites#
- A solved
JsonProject:solvehas run with your data. - The data has
resourcesandassignments, so there's overallocation to level. - The project is forward-scheduled.
levelrefusesconfig.schedule_from_end: truewith avalidationerror at the pathconfig.schedule_from_end.
Steps#
-
Clone the solved project:
const = ; -
Level the clone. The original keeps its dates, its baseline and its overallocation:
const = ;unwrapparses the envelope and throws onok: false. It's defined in the full example below. If the call fails, freedraftbefore you rethrow. -
Show the proposal.
proposal.updateslists the tasks leveling moved, with their new dates,leveling_delayand, when they changed,pauses. 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. -
Show what leveling couldn't fix.
proposal.overallocationsholds the windows left after leveling. Each window has areason, such asfixed-taskorpriority-1000. Bothoverallocationsandwindowscan be absent, so default them: -
Apply the user's choice:
- Accept: free the original and keep the clone in its place. The clone holds the leveled baseline.
- Reject: free
draft. Nothing else needs undoing.
Swap only if the original hasn't been edited since you cloned it. Otherwise the proposal was computed from an older state, so level a new clone.
The full example levels two tasks that book the same developer full time on Monday and Tuesday:
const = ;
// Two 2-day tasks, both booked full time on dev1 from Monday, August 10, 2026,
// on the default calendar.
const = ;
let = new;
Result#
Run the example with node. It 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 matches proposal: true
B waits two days for A, so its leveling_delay is 2. Until you swap, the original still reports the Monday-Tuesday window on dev1, and a solve without data 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 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 of EvaluateOptions instead. See Evaluating alternatives. For options, reasons and splits, see Leveling resources.