[Canonical page](<https://docs.dhtmlx.com/planning-engine/js/resources-and-assignment/suggesting-assignments/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# Suggesting assignments

This guide shows how to let Planning Engine pick who works on a task. It covers filling open positions, fixing assignments that no longer fit, moving work off overloaded people, and reading and committing the proposal.

## How auto-assignment works

[`project.suggestAssignments(slots, options)`](<https://docs.dhtmlx.com/planning-engine/js/api/project-suggest-assignments.md>) takes a list of **slots** and returns a proposal. The call is synchronous and never changes the project. You decide what to commit.

A slot is one position on one task: "task C needs one person, and dev1 or dev2 can do it". It's a plain object with the task, the list of eligible resources (`allowed`) and, when someone already fills it, the assignment that does. The engine doesn't know about skills. If you model skills, [`project.slots(pool, requirements)`](<https://docs.dhtmlx.com/planning-engine/js/api/project-slots.md>) builds the slots for you (see [Skills and requirements](<https://docs.dhtmlx.com/planning-engine/js/resources-and-assignment/skills-and-requirements.md>)).

Every slot is in one of three states, judged from its current resource:

| State | Meaning | `targets` value | What the call does |
|---|---|---|---|
| empty | no assignment | `"empty"` | fills it with the cheapest eligible resource |
| broken | held by a resource outside `allowed` | `"broken"` | moves it to the cheapest eligible resource |
| valid | held by a resource in `allowed` | `"valid"` | moves it only if another resource is strictly cheaper |

The `targets` option says which states to act on. The default is `["empty"]`: fill open positions and leave the rest alone.

The call is greedy. It visits slots one at a time and tries every eligible resource on a working copy of the project. Each try is scheduled and scored the same way [`evaluate`](<https://docs.dhtmlx.com/planning-engine/js/resources-and-assignment/evaluating-alternatives.md>) scores a candidate: finish delay plus overload plus a heavy penalty for conflicts. The cheapest resource wins, and later slots build on the earlier picks.

The result has two main parts. `changes` is a [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/js/api/types/scheduling-changes.md>) object you can pass straight to [`apply`](<https://docs.dhtmlx.com/planning-engine/js/api/project-apply.md>). `steps` logs every decision with the cost before and after, so a UI can explain each pick.

`suggestAssignments` never removes an assignment. It can add one (fill) or change the resource of one (repair, rebalance). A slot it can't fix is reported, and you decide what to do with it.

The proposal is built on the solved baseline, so the project must be solved and clean. Failures are thrown synchronously:

| Failure | Error |
|---|---|
| Project not solved yet, or edited with `apply` since the last solve | [`ProjectError`](<https://docs.dhtmlx.com/planning-engine/js/api/types/errors.md#projecterror>), `code: "no-baseline"` |
| `baselineId` doesn't name the current baseline | `ProjectError`, `code: "stale-baseline"` |
| Bad slot (see [Slots](<https://docs.dhtmlx.com/planning-engine/js/resources-and-assignment/suggesting-assignments.md#slots>)) | [`InputError`](<https://docs.dhtmlx.com/planning-engine/js/api/types/errors.md#inputerror>), `path` like `"slots[1].allowed[0]"` |
| Bad option value: unknown `targets` value, duplicate target, `passes` below 1, negative penalty, unknown id in `fixed` | `InputError`, `kind: "validation"` |
| Unknown option key | `InputError`, `kind: "parse"` |

See [Handling errors](<https://docs.dhtmlx.com/planning-engine/js/error-handling.md>) for the error classes.

## Slots

A [`Slot`](<https://docs.dhtmlx.com/planning-engine/js/api/types/slot.md>) is `{ id, task, allowed, value?, assignment? }`. The order of `allowed` is the tie-break: when two resources cost the same, the earlier one wins. A new assignment gets `value` units, 1 by default.

The slot id becomes the id of the assignment that fills it. On the next run, pass that id back in `assignment`, so the slot counts as filled and isn't filled twice.

```js
import { Project } from "plen-js";

const data = {
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "C", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  // dev1 works on A and B at the same time.
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
};

const project = new Project();
project.solve(data);

// Task C needs one person: dev1 or dev2.
const slots = [{ id: "sC", task: "C", allowed: ["dev1", "dev2"] }];
const result = project.suggestAssignments(slots);

for (const add of result.changes.assignments?.add ?? []) {
  console.log(`${add.id} on ${add.task}: ${add.resource}`);
}
```

This prints `sC on C: dev2`. dev1 is already double-booked on A and B, so putting C on dev1 adds two more days of overload. dev2 is free.

To describe a filled slot, set `assignment`. The assignment must be active and on the slot's task:

```js
const slot = { id: "sB", task: "B", allowed: ["dev1", "dev2", "dev3"], assignment: "aB" };
```

The call checks every slot before it does any work. It throws an [`InputError`](<https://docs.dhtmlx.com/planning-engine/js/api/types/errors.md#inputerror>) on a duplicate slot id, an unknown or summary task, an unknown resource in `allowed`, a `value` that isn't a finite number above 0, or an `assignment` that isn't active or is on another task. The error `path` points at the slot field, for example `slots[0].allowed[0]`. The full list is on the [`Slot` reference](<https://docs.dhtmlx.com/planning-engine/js/api/types/slot.md>).

If you model skills, don't build slots by hand. [`project.slots(pool, requirements)`](<https://docs.dhtmlx.com/planning-engine/js/api/project-slots.md>) builds them from a pool of workers and task requirements, and binds existing assignments to their slots:

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [{ id: "C", start_date: "2026-08-10 00:00", duration: 2 }],
  resources: [{ id: "dev1" }, { id: "dev2" }],
});

const pool = {
  workers: [
    { resource: "dev1", skills: [{ id: "qa" }] },
    { resource: "dev2" },
  ],
};
const requirements = [{ id: "qa", task: "C", matches: [{ skill: "qa" }] }];

// One slot "qa#1" on C, with dev1 as the only eligible resource.
const slots = project.slots(pool, requirements);
const result = project.suggestAssignments(slots);
console.log(`${result.steps.length} step(s)`); // 1 step(s)
```

## Options

Pass only the options you need; every field is optional.

| Option | Default | Use it to |
|---|---|---|
| `targets` | `["empty"]` | choose which slot states to act on; `[]` only reports broken slots |
| `fixed` | `[]` | keep listed assignments where they are |
| `newResourcePenalty` | `0` | trade balance against headcount (see [How picks are made](<https://docs.dhtmlx.com/planning-engine/js/resources-and-assignment/suggesting-assignments.md#how-picks-are-made>)) |
| `passes` | `1` | rebalance valid slots more than once |
| `level` | `false` | score each candidate after leveling |
| `clearFirst` | `false` | score against a copy with stored leveling delays cleared |
| `baselineId` | none | throw `stale-baseline` if the project changed |

All options are on the [`suggestAssignments` reference](<https://docs.dhtmlx.com/planning-engine/js/api/project-suggest-assignments.md>).

### Rebalancing filled slots

Add `"valid"` to `targets` to move work off overloaded people. Rebalancing runs after filling and repairing, so it also sees the slots that were just filled.

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "C", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
});

const slots = [
  { id: "sC", task: "C", allowed: ["dev1", "dev2"] },
  { id: "sB", task: "B", allowed: ["dev1", "dev2", "dev3"], assignment: "aB" },
];

const result = project.suggestAssignments(slots, { targets: ["empty", "valid"] });
for (const update of result.changes.assignments?.update ?? []) {
  console.log(`${update.id}: ${update.resource}`); // aB: dev3
}
```

The call fills `sC` with dev2, then moves `aB` from dev1 to dev3. dev2 isn't a good pick for B anymore, because it now works on C. The proposal holds one add (`sC`) and one update (`aB` to dev3).

A valid slot moves only on strict improvement: on a tie, the current resource stays. With `newResourcePenalty` at `0`, a valid slot is skipped when its current resource isn't overloaded during the task. One pass is often enough. When a later move makes an earlier pick worse, raise `passes`. The loop stops early after a pass that moves nothing.

### Keeping people in place

List assignment ids in `fixed` to keep them out of every pass, whatever the load:

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "C", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
});

const slots = [
  { id: "sC", task: "C", allowed: ["dev1", "dev2"] },
  { id: "sB", task: "B", allowed: ["dev1", "dev2", "dev3"], assignment: "aB" },
];

const result = project.suggestAssignments(slots, {
  targets: ["empty", "valid"],
  fixed: ["aB"], // dev1 stays on B
});
const { add = [], update = [] } = result.changes.assignments ?? {};
console.log(`${add.length} add(s), ${update.length} update(s)`); // 1 add(s), 0 update(s)
```

`sC` is still filled with dev2, but `aB` stays on dev1. A fixed resource still counts as being on its task, and a fixed slot that is broken is still listed in `invalid`. An id in `fixed` must name an active assignment, otherwise the call throws an [`InputError`](<https://docs.dhtmlx.com/planning-engine/js/api/types/errors.md#inputerror>) at `fixed[i]`. The id doesn't have to be bound to a slot.

### Repairing broken slots

A slot breaks when its resource drops out of `allowed`, for example after a requirement or a skill grade changed. Run with `targets: []` first to only check, then with `"broken"` to fix:

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
});

// B now needs dev2 or dev3, but dev1 holds it.
const slots = [{ id: "sB", task: "B", allowed: ["dev2", "dev3"], assignment: "aB" }];

const report = project.suggestAssignments(slots, { targets: [] });
console.log("broken:", report.invalid); // broken: [ 'sB' ]

const result = project.suggestAssignments(slots, { targets: ["broken"] });
for (const step of result.steps) {
  console.log(`${step.slot}: ${step.fromResource} -> ${step.toResource}`); // sB: dev1 -> dev2
}
```

A repair always moves the slot. It takes the cheapest eligible resource, even if keeping the current one would cost less. A broken slot is visited once, with no retry. If no eligible resource can take it, it keeps its assignment and stays in `invalid`.

### Scoring after leveling

By default each candidate is only scheduled, so overload shows up as cost. With `level`, each candidate is also leveled with those [leveling options](<https://docs.dhtmlx.com/planning-engine/js/api/types/leveling-options.md>) and scored on the leveled plan, where overload turns into delay. The score then tells you how much later the project would finish with each pick.

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "C", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
});

const slots = [{ id: "sC", task: "C", allowed: ["dev1", "dev2"] }];
const result = project.suggestAssignments(slots, { level: {} });

const finish = result.proposed.leveled?.finish.project;
if (finish) {
  console.log(`leveled finish: ${finish.date} (${finish.delta} days later)`);
  // leveled finish: 2026-08-14 00:00 (2 days later)
}
```

`sC` goes to dev2. The leveled finish is two days later than the accepted plan, because leveling still has to separate A and B on dev1.

:::note
Leveled metrics have the same fields as [`Metrics`](<https://docs.dhtmlx.com/planning-engine/js/api/types/metrics.md>) plus `converged`, `rounds` and `windows`.
:::

Each pick builds on the scheduled copy, not the leveled one, so leveling delays don't add up across picks. Every candidate runs a full level, so keep leveled scoring for small sets of slots.

If the project holds delays from an earlier `level` run, those delays can hide overload, and the rebalance skip rule then sees nothing to fix. Set `clearFirst: true` to score against a copy with the delays and pauses cleared. `changes` then carries a `tasks.update` for each cleared task, so committing it reproduces the cleared state.

## How picks are made

Slots are visited in a fixed order, set once from the accepted plan: task start, then task order in the data, then the order of the slots you passed. Picks that move dates don't change the order. The order matters, because the result is greedy: an early slot takes the best resource, and later slots work around it.

The call runs in passes:

1. Pass 0 fills empty slots and repairs broken ones, if those states are targeted.
2. Passes 1 to `passes` rebalance every valid slot, if `"valid"` is targeted.

For each slot the call tries every resource in `allowed`, except duplicates and resources already on the task (a task never gets the same person twice). It schedules each try on a copy of the working state and computes its cost:

```text
cost = evaluate cost against the accepted plan
     + newResourcePenalty × (people in use now − people in use in the accepted plan)
```

The evaluate cost is finish delay plus overload plus 1000 per conflict or cycle; see [Evaluating alternatives](<https://docs.dhtmlx.com/planning-engine/js/resources-and-assignment/evaluating-alternatives.md>). It's always measured against the accepted plan, never against the previous pick.

"People in use" counts the resources that have at least one active assignment, out of those in any slot's `allowed` plus the current holders of filled slots. Once someone is brought in, later slots can use them for free. Moving someone's last assignment away lowers the cost.

`newResourcePenalty` is the one lever between balance and headcount. At `0` the call spreads work to idle people. A large value keeps work on the people who are already busy, as long as their extra overload costs less than the penalty:

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "C", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
});

const slots = [
  { id: "sC", task: "C", allowed: ["dev1", "dev2"] },
  { id: "sB", task: "B", allowed: ["dev1", "dev2", "dev3"], assignment: "aB" },
];

for (const penalty of [0, 0.5, 5]) {
  const result = project.suggestAssignments(slots, {
    targets: ["empty", "valid"],
    newResourcePenalty: penalty,
  });
  console.log(`penalty ${penalty}: ${result.proposed.resources} in use, cost ${result.proposed.cost}`);
}
```

```text
penalty 0: 3 in use, cost 0
penalty 0.5: 3 in use, cost 1
penalty 5: 1 in use, cost 4
```

At `0.5`, two new people cost 1, and removing four days of overload is worth more. At `5`, one new person would cost more than the two extra days of overload on dev1, so C goes to dev1 and nobody else is brought in. With a penalty above `0`, valid slots aren't skipped when their holder isn't overloaded: freeing a person is a gain on its own.

A candidate that can't be applied or scheduled is dropped. An empty slot with no candidate left goes to `unfilled`.

## Reading the proposal

The result has everything a UI needs to show and explain the proposal:

- `changes` - the net edit: one add per filled slot, one update per moved assignment (even after several passes), and the `clearFirst` clears. Its `baselineId` is set.
- `steps` - every decision that changed the working state, in order.
- `unfilled` - targeted empty slots left empty.
- `invalid` - slots whose resource is outside `allowed` at the end, whatever `targets` was.
- `baseline` and `proposed` - cost and people in use before and after. `proposed` also carries the scheduled [`Metrics`](<https://docs.dhtmlx.com/planning-engine/js/api/types/metrics.md>) and, with `level`, the leveled ones.

A step has no kind field. Read the kind from `fromResource` and `pass`:

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "C", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
});

const slots = [
  { id: "sC", task: "C", allowed: ["dev1", "dev2"] },
  { id: "sB", task: "B", allowed: ["dev1", "dev2", "dev3"], assignment: "aB" },
];
const result = project.suggestAssignments(slots, { targets: ["empty", "valid"] });

console.log(`cost ${result.baseline.cost} -> ${result.proposed.cost}`);
for (const step of result.steps) {
  let action;
  if (step.fromResource === null) action = "fill";
  else if (step.pass === 0) action = `repair from ${step.fromResource}`;
  else action = `rebalance from ${step.fromResource} (pass ${step.pass})`;
  console.log(
    `${step.slot} on ${step.task}: ${action} to ${step.toResource}, cost ${step.cost.before} -> ${step.cost.after}`,
  );
}
```

```text
cost 2 -> 0
sC on C: fill to dev2, cost 2 -> 2
sB on B: rebalance from dev1 (pass 1) to dev3, cost 2 -> 0
```

The step costs form a chain: the first `before` is `baseline.cost`, and each `before` is the previous step's `after`. The baseline costs 2 because dev1 is already overloaded for two days. Filling C doesn't make that worse, and moving B to dev3 removes it.

`proposed.scheduled` is the full `Metrics` of the final state, with finish, overload per resource, conflicts and cycles. Its finish dates follow the project's date setting, like every other result date. See the [`suggestAssignments` reference](<https://docs.dhtmlx.com/planning-engine/js/api/project-suggest-assignments.md>) for every result field.

## Committing

Pass `result.changes` to [`apply`](<https://docs.dhtmlx.com/planning-engine/js/api/project-apply.md>), then reschedule. If you scored with `level`, run [`level`](<https://docs.dhtmlx.com/planning-engine/js/api/project-level.md>) with the same options instead of [`solve(null)`](<https://docs.dhtmlx.com/planning-engine/js/api/project-solve.md>).

```js
import { Project } from "plen-js";

const project = new Project();
project.solve({
  config: { use_calendars: false },
  tasks: [
    { id: "A", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "B", start_date: "2026-08-10 00:00", duration: 2 },
    { id: "C", start_date: "2026-08-10 00:00", duration: 2 },
  ],
  resources: [{ id: "dev1" }, { id: "dev2" }, { id: "dev3" }],
  assignments: [
    { id: "aA", task: "A", resource: "dev1", value: 1 },
    { id: "aB", task: "B", resource: "dev1", value: 1 },
  ],
});

const options = { targets: ["empty", "valid"] };
const result = project.suggestAssignments(
  [
    { id: "sC", task: "C", allowed: ["dev1", "dev2"] },
    { id: "sB", task: "B", allowed: ["dev1", "dev2", "dev3"], assignment: "aB" },
  ],
  options,
);

const report = project.apply(result.changes);
if (report.rejected.length > 0) {
  throw new Error("proposal rejected, resync the project");
}
project.solve(null);

// Next run: sC is now the id of the assignment on C.
const again = project.suggestAssignments(
  [
    { id: "sC", task: "C", allowed: ["dev1", "dev2"], assignment: "sC" },
    { id: "sB", task: "B", allowed: ["dev1", "dev2", "dev3"], assignment: "aB" },
  ],
  options,
);
console.log(`${again.steps.length} step(s)`); // 0 step(s): nothing left to improve
```

`changes.baselineId` names the plan the proposal was built on. If the project changed in between, `apply` throws a [`ProjectError`](<https://docs.dhtmlx.com/planning-engine/js/api/types/errors.md#projecterror>) with `code: "stale-baseline"` instead of committing an outdated proposal. A rejected operation sets `needsResync`; see [Recovering from rejected changes](<https://docs.dhtmlx.com/planning-engine/js/how-to/recover-from-rejected-changes.md>).

The new assignment takes the slot id, so the slot keeps its binding after the commit. On the next run, pass that id in `assignment`, as above. [`project.slots()`](<https://docs.dhtmlx.com/planning-engine/js/api/project-slots.md>) binds slots this way for you. A slot id that is already the id of another assignment makes the call throw an `InputError` at `slots[i].id`. Without that check, every add for the slot would be rejected as a duplicate id, and the slot would stay unfilled without a reason.

You can also commit part of a proposal. `changes` is a plain [`SchedulingChanges`](<https://docs.dhtmlx.com/planning-engine/js/api/types/scheduling-changes.md>) object, so drop the adds or updates the user declines before you call `apply`.

The committed plan matches `proposed` when `config.gap_behavior` is `"compress"`. With the default `"preserve"`, it can differ slightly. The call reschedules after each pick, while the commit reschedules once, and preserved dates depend on the path taken. Treat `proposed` as an estimate in that mode. See [`SchedulingConfig`](<https://docs.dhtmlx.com/planning-engine/js/api/types/scheduling-config.md>).

[`suggestAssignments`](<https://docs.dhtmlx.com/planning-engine/js/api/project-suggest-assignments.md>) runs one schedule (and one level, with `level`) per slot and candidate, all on the calling thread, and blocks the event loop until it returns. On large projects, run it in a Worker; see [Running in a worker](<https://docs.dhtmlx.com/planning-engine/js/how-to/run-in-a-worker.md>).
