JsonProject.apply#
Writes the edits of a SchedulingChanges payload into the accepted state of a JsonProject and marks it unsolved. It doesn't schedule anything: follow it with solve without data or with level to get the new dates. To see what an edit would do without committing it, use preview.
Signature#
changes_json: string: string
Synchronous and CPU-bound. Edits the handle in place. In the browser build, call it only after init() has resolved.
Request#
| Argument | Payload | Required | Description |
|---|---|---|---|
changes_json |
SchedulingChanges |
yes | The edits to commit. The order the operations run in is on the SchedulingChanges page. |
Behavior#
- Operations are partially accepted. Each one is tried on its own, so a rejected operation leaves no partial edit and the operations around it still apply. Rejections go into
rejectedof a success envelope, not into an error envelope. - Any rejection sets
needsResync. After that,solvewithout data,applyandlevelreturnneeds-resyncuntil a successfulsolvewith full data. - The project is unsolved afterwards.
preview,loadProfile,evaluate,slotsandsuggestAssignmentsreturnno-baselineuntil the next solve, and every earlierbaselineIdis stale. - Tasks added or updated by successful operations are reported by the next acyclic
solvewithout data, orlevel, even when the planner leaves them where the edit put them. They accumulate across severalapplycalls until then. - A
clone()made before the call doesn't see the edit.
Response#
The success envelope carries an ApplyReport. The envelope shape is described in Wire format.
ApplyReport#
Which operations of the change set took effect, which were refused, and what the accepted ones changed beyond the records they named. All fields are always present.
| Field | Type | Description |
|---|---|---|
applied |
{ path: string }[] |
Accepted operations, in the order they ran. path names the operation, e.g. tasks.update[0]. |
rejected |
{ path: string, message: string }[] |
Refused operations, in the order they ran, each with the reason. Empty when the whole change set was accepted. |
effects |
ChangeEffects |
Ids removed, generated or dropped by the accepted operations. |
needsResync |
boolean |
true when rejected isn't empty. |
revision |
number |
The project's state revision after this call. Every apply raises it, so a larger value from the same handle means a later state. |
Every operation of the change set appears in exactly one of applied and rejected.
ChangeEffects#
Side effects of the accepted operations, for keeping the caller's own copy of the data in sync. Every field is an array of Ids, always present and empty when there was no such effect. A rejected operation adds nothing.
| Field | Type | Description |
|---|---|---|
removedTasks |
Id[] |
Each task named in tasks.remove, followed by its descendants, which are removed with it. |
removedLinks |
Id[] |
Links named in links.remove, and links removed because their source or target task was removed. |
generatedLinks |
Id[] |
Ids given to added links that had no id, in the form $generated_link_1, $generated_link_2, and so on. |
droppedLinks |
Id[] |
Links still in the project that became inactive because of this change set. Links that were already inactive aren't listed. |
removedAssignments |
Id[] |
Assignments named in assignments.remove, and assignments removed because their task or resource was removed. |
generatedAssignments |
Id[] |
Ids given to added assignments that had no id. |
droppedAssignments |
Id[] |
Assignments still in the project that became inactive because of this change set. |
Errors#
| Error | When |
|---|---|
kind: "project", code: "stale-baseline" |
baselineId in the change set doesn't name the current baseline. Nothing is applied. |
kind: "project", code: "needs-resync" |
An earlier apply rejected an operation and no solve with data followed. Checked before baselineId, so it wins over stale-baseline. |
kind: "parse" |
changes_json isn't valid JSON, has the wrong JSON type, misses a required field, or has an unknown field in the change set or its buckets. |
kind: "validation" |
A value the decoder rejects, such as an invalid date or an unknown enum string (path: null). Nothing is applied. |
Errors come back in the returned envelope; the call doesn't throw for bad input. Calling it on a freed handle throws at host level. See Error handling.
A priority outside 0..1000 or a malformed hour range fails the whole call with a validation error that has no path. In apply, this means no operation from that change set is applied.
A start date that falls on non-working time is kept unsnapped when the task has no predecessor. The end is computed forward from it on the working calendar.
Example#
Request (changes_json), sent after a solve that returned baselineId "1-b0605af8cba3d7c9":
Response:
The project has no task gone, so the removal is rejected and needsResync is set. The update and the link addition still apply.
Host call in Node, resyncing with full data after a rejection:
const = ;
const = ;
const = new;
Related#
SchedulingChanges- the change setJsonProject.solve- reschedule after the editsJsonProject.preview- try the edits without committing them- Editing a Project - change sets, applying and rescheduling
- Recover from rejected changes - handling
rejectedoperations andneeds-resync