Skip to main content

api.getTaskResources(id)

PRO

The functionality is available in PRO Edition only

Description​

Gets all resources assigned to a task

Usage​

api.getTaskResources(id): TResourceAssignment[];

Parameters​

  • id - the id of the task

Returns​

The method returns an array of objects for each resource assigned to the specified task. Returns an empty array if no resources are assigned.

Each object is a combination of the assignment and resource data. It contains all resource properties (such as id, name, role, etc.) together with the assignment fields:

  • units — allocation percentage (0–100)
  • assignmentId — the ID of the assignment record

Example​

<script>
import { getData } from "../data";
import { Gantt } from "@svar/svelte-gantt";

const data = getData();

function init(api) {
const resources = api.getTaskResources(1);
// [{ id: "r1", name: "Alice", role: "Developer", units: 100, assignmentId: 1 }, ...]
console.log("Assigned resources:", resources);
}
</script>

<Gantt
tasks={data.tasks}
links={data.links}
scales={data.scales}
resources={data.resources}
assignments={data.assignments}
{init}
/>

Related articles: