[Canonical page](<https://docs.dhtmlx.com/planning-engine/java/how-to/reschedule-a-branch/>)
[Full documentation index](<https://docs.dhtmlx.com/planning-engine/llms.txt>)


# Reschedule a branch

Reschedule one task and the work that depends on it, and leave the rest of the project where it is.

The scope is the task you name, its summary ancestors and descendants, and its successors through links. Tasks outside the scope keep their dates.

## Steps

1. Build a [`Subtree`](<https://docs.dhtmlx.com/planning-engine/java/api/project/subtree.md>) for the task the branch starts from, and set it on [`SolveOptions`](<https://docs.dhtmlx.com/planning-engine/java/api/project/solve-options.md>). `new Subtree(id)` sets `inclusive = true`, so predecessors of the task and their branches join the scope too:

   ```java
   var options = new SolveOptions().withSubtree(new Subtree(Id.str("design")));
   ```

   To follow only the task's own branch, set `inclusive` to `false`. The task itself stays in scope either way:

   ```java
   var subtree = new Subtree(Id.str("design")).withInclusive(false);
   ```

2. Pass the options to [`Project#solve`](<https://docs.dhtmlx.com/planning-engine/java/api/project-solve.md>). Pass the [`ProjectData`](<https://docs.dhtmlx.com/planning-engine/java/api/data/project-data.md>) on the first load, or `null` to reschedule the current state:

   ```java
   var result = project.solve(null, options);
   ```

3. Write the entries of `result.updates` back to your model. Each entry is a task in the scope that moved. The scoped dates become the accepted baseline.

The full example below has two independent chains, `backend → api` and `design → ui`. Both successors start too early. The scoped solve fixes only the `design` branch:

```java
import java.util.List;
import org.dhtmlx.plen.*;

public class RescheduleBranch {
  static TaskData task(String id, Moment start, double duration) {
    return new TaskData(Id.str(id)).withStartDate(start).withDuration(duration);
  }

  static LinkData link(String id, String source, String target) {
    return new LinkData()
        .withId(Id.str(id))
        .withSource(Id.str(source))
        .withTarget(Id.str(target))
        .withLinkType(LinkType.FS);
  }

  public static void main(String[] args) throws Exception {
    var jan1 = Moment.fromYmdHm(2026, 1, 1, 0, 0);

    var data = new ProjectData()
        .withTasks(List.of(
            task("backend", jan1, 2.0),
            task("api", jan1, 1.0),
            task("design", jan1, 3.0),
            task("ui", jan1, 1.0)))
        .withLinks(List.of(
            link("l1", "backend", "api"),
            link("l2", "design", "ui")));
    // 24/7 time keeps the example dates easy to check.
    data.config.useCalendars = false;

    var options = new SolveOptions().withSubtree(new Subtree(Id.str("design")));

    var project = new Project();
    var result = project.solve(data, options);

    for (var m : result.updates) {
      if (m.startDate != null && m.endDate != null) {
        System.out.println(m.id + " " + m.startDate + ".." + m.endDate);
      }
    }
  }
}
```

## Preview a branch

To see what rescheduling a branch would do without changing the project, set the same `subtree` on [`PreviewOptions`](<https://docs.dhtmlx.com/planning-engine/java/api/project/preview-options.md>) and call [`Project#preview`](<https://docs.dhtmlx.com/planning-engine/java/api/project-preview.md>):

```java
var preview = project.preview(
    new SchedulingChanges(),
    new PreviewOptions().withSubtree(new Subtree(Id.str("backend"))));
```

The preview scope applies to that call only. It doesn't touch the baseline or the cached solve result. A preview scope can also name a task that the same `changes` add.

## Things to know

- Tasks outside the scope don't move until you solve them. In the example, the next `project.solve(null, new SolveOptions())` moves only `api`, because `ui` is already accepted.
- The result cache is keyed on the whole [`SolveOptions`](<https://docs.dhtmlx.com/planning-engine/java/api/project/solve-options.md>), compared by value. A different `subtree` replans from the accepted dates. The same `subtree` again returns the cached result.
- With [`includeUnchanged`](<https://docs.dhtmlx.com/planning-engine/java/how-to/load-all-task-dates.md>), a scoped solve reports every task in the scope, plus the out-of-scope tasks a sparse scoped solve would report.
- On a project with a dependency cycle, nothing is scheduled, scoped or not. Check [`result.cycles`](<https://docs.dhtmlx.com/planning-engine/java/api/results/schedule-result.md#cycles>).
- An unknown or unscheduled task in `subtree.task` throws [`InputException`](<https://docs.dhtmlx.com/planning-engine/java/api/errors/input-exception.md>) with `path` set to `subtree.task`. The project keeps its previous state and cached result. See [Error handling](<https://docs.dhtmlx.com/planning-engine/java/error-handling.md>).

## Result

The example prints one line. Only `ui` moves, to start after `design` ends. `api` still overlaps `backend`:

```text
ui 2026-01-04 00:00..2026-01-05 00:00
```

Without `subtree`, the same solve also moves `api` to `2026-01-03 00:00`.
