Timill Platform Documentation

Cookbook

Worked, verified examples for every kind of Timill script — automations, item hooks, charts, and widgets.

Note

Automation, item-hook and Gonja examples below are the exact set shown in the in-app editor’s collapsible cheatsheet (the panel under the Monaco editor) — copy-paste them from either place. The chart examples here are additional and are not currently surfaced in that in-app panel.

Automation scripts (JavaScript)#

Group-level automation scripts — manual, scheduled, or event-triggered — run with the writable JavaScript surface. Only a script triggered by an item’s own event gets that item as item; manual and scheduled runs don’t, so guard for it first.

Loop over a query result#

queryItems returns Item[] — for-of gives you a typed item with all properties.

for (const it of group.queryItems("completedDate:$empty")) {
  log(it.title, it.status);
}

Act on the item that raised an event#

An event script raised by an item action gets that item as item; manual and scheduled runs do not, so guard first.

if (typeof item !== "undefined") {
  log("event on", item.tag, item.title);
  item.addComment("Processed by automation");
}

Update queried items#

Items from queryItems are writable; each setter saves on its own and returns {success, error}.

for (const it of group.queryItems("dueDate:<$today AND completedDate:$empty")) {
  const r = it.setField("priority", "high");
  if (!r.success) log(it.tag, r.error);
}

Item scripts: save hooks & menu actions (JavaScript)#

Item scripts run with item bound to the item in scope. Setter semantics differ by trigger: in a save hook the setters are tracked and persisted together with the triggering change (save() is safe but optional); a menu script persists each write immediately (save() is not needed).

Set a field on the saved item#

setField works for default and custom fields; the hook persists the change with the triggering save.

item.setField("priority", "high");
item.save();

React to the item’s current values#

Read properties (title, status, isCompleted, …) and getField(id), then branch before writing.

if (item.getField("priority") === "high" && !item.isCompleted) {
  item.setTitle("🔥 " + item.title);
}
item.save();

Move the status#

setStatus takes the status ID from the item type’s workflow.

if (item.status !== "done") {
  item.setStatus("done");
}
item.save();

Set assignee and due date#

setAssignedTo takes a user ID; setDueDate takes an ISO 8601 date string.

item.setAssignedTo(item.createdBy);
item.setDueDate("2026-08-01T00:00:00Z");
item.save();

Add a comment#

Comments are created immediately — no save() needed.

item.addComment("Reviewed automatically ✔");

Attach a file downloaded from an API#

base64() keeps the bytes intact (body is text); works for the attachments field and custom attachment fields. Saved immediately.

const r = fetch("https://api.example.com/invoices/42.pdf", {
  headers: { Authorization: "Bearer " + secrets.get("API_TOKEN") }
});
if (r.ok) {
  const res = item.addAttachment("attachments", { filename: "invoice-42.pdf", base64: r.base64() });
  if (!res.success) log("attach failed:", res.error);
}

Send the item’s files to an API#

getField lists the files; readAttachment gives each one’s content as text(), base64() or bytes().

for (const a of item.getField("attachments")) {
  const file = item.readAttachment(a.id);
  fetch("https://api.example.com/documents", {
    method: "POST",
    body: { name: a.filename, contentType: a.contentType, data: file.base64() }
  });
}

Log for the execution history#

log output shows up in the script’s run logs — handy for debugging conditions.

log("hook ran for", item.title, "status:", item.status);

Charts#

Chart scripts get the read-only surface — no setters, no fetch, no secrets — and must end on the ECharts option as their final expression (no return). See Scripted Charts for the full contract.

Pie of items by status, slices clickable#

Count with a plain loop, then hand [{name, value, url}] to createPieChart. item.status is a status ID — map ids to names with group.getStatuses(itemTypeId) when charting one type. A relative url per point makes the slice a drill-down link to the filtered items page; leave it off buckets with no query equivalent. The helper call is the script’s final expression: no return.

const counts = {};
for (const it of group.queryItems("")) {
  const key = it.status || "none";
  counts[key] = (counts[key] || 0) + 1;
}
const data = Object.entries(counts).map(([name, value]) => {
  const point = { name, value };
  if (name !== "none") {
    point.url = "/" + groupId + "/items/all?q=" + encodeURIComponent("status:" + name);
  }
  return point;
});
echarts.createPieChart(data, { title: "Items by status" });

Bar of items per person#

createBarChart takes the numbers plus a categories option; resolve user ids to names with group.getMemberById.

const counts = {};
for (const it of group.queryItems("completedDate:$empty")) {
  const m = it.assignedTo ? group.getMemberById(it.assignedTo) : null;
  const name = m ? m.name : "Unassigned";
  counts[name] = (counts[name] || 0) + 1;
}
echarts.createBarChart(Object.values(counts), {
  title: "Open items per person",
  categories: Object.keys(counts),
});

Raw ECharts option for full control#

Anything the helpers can’t express: build the option object and end the script with it. Dates on items are ISO strings, so slicing gives calendar buckets.

const counts = {};
for (const it of group.queryItems("created:>=$today-6m")) {
  const month = it.createdAt.slice(0, 7);
  counts[month] = (counts[month] || 0) + 1;
}
const months = Object.keys(counts).sort();
const option = {
  title: { text: "Items created per month" },
  tooltip: { trigger: "axis" },
  xAxis: { type: "category", data: months },
  yAxis: { type: "value" },
  series: [{ type: "line", smooth: true, data: months.map((m) => counts[m]) }],
};
option;

Scatter of priority vs due date#

Not every field belongs on an axis as-is — map a dropdown value to a number first, same as any other transform. Points with no due date are skipped, and each point still carries a drill-down url.

const priorityScore = { critical: 4, high: 3, medium: 2, low: 1 };
const data = group
  .queryItems("dueDate:$filled")
  .map((it) => ({
    value: [Date.parse(it.dueDate), priorityScore[it.getField("priority")] || 0],
    url: "/" + groupId + "/items/all?q=" + encodeURIComponent("tag:" + it.tag),
  }));
echarts.createScatterChart(data, { title: "Priority vs due date" });

Widgets (Gonja/Jinja2)#

Scripted widgets render a Jinja2-compatible template to HTML using the Gonja engine. group/user/pageVars are read-only, same data shapes as charts; there is no item global on a page widget.

Loop over a query result#

queryItems returns an array — wrap it in {% for %} to access each item’s properties. completedDate:$empty selects the items that are still open in every item type; status ids are per item type.

{% for it in group.queryItems("completedDate:$empty") %}
  <li>{{ it.title }} — {{ it.renderField("status") }}</li>
{% endfor %}

Empty-state with {% else %}#

A for-loop’s {% else %} block renders when the sequence is empty — no length check needed.

{% for it in group.queryItems("completedDate:$empty") %}
  <li>{{ it.title }}</li>
{% else %}
  <li>No open items 🎉</li>
{% endfor %}

Filter rows inside the loop#

Combine {% for %} with {% if %} to render only the items you care about.

{% for it in group.queryItems("") %}
  {% if it.isCompleted %}<li>✓ {{ it.title }}</li>{% endif %}
{% endfor %}

Count results#

Gonja’s built-in length filter counts any query result. Add AND assignee:$me to count only the viewer’s items.

{{ group.queryItems("completedDate:$empty") | length }} open items

Group and aggregate#

api.groupBy / api.aggregate work like their JavaScript twins and read an item’s top-level keys (status, type, assignedTo, …).

{% set byStatus = api.groupBy(group.queryItems(""), "status") %}
{% for status, items in byStatus.items() %}
  <li>{{ status }}: {{ items | length }}</li>
{% endfor %}

Show the current user#

user holds the viewer — read properties directly (no parens) and branch with {% if %}.

<p>Hello, {{ user.name }}!</p>
{% if not user.isActive %}<em>(inactive)</em>{% endif %}

List group members#

getMembers() returns each member as a user object you can loop over.

{% for m in group.getMembers() %}
  <li>{{ m.name }} — {{ m.email }}</li>
{% endfor %}

Format dates#

date(value, layout) / datetime(value, layout) take a Go layout string; omit it for the default.

{% for it in group.queryItems("") %}
  <li>{{ it.title }} — {{ date(it.createdAt) }} → {{ date(it.createdAt, "Jan 2, 2006") }}</li>
{% endfor %}

Read a field value#

getField returns the raw value (auto-escaped); renderField returns the formatted HTML the UI uses, emitted as-is (no |safe needed).

{% for it in group.queryItems("") %}
  <li>{{ it.title }} — priority: {{ it.getField("priority") }} {{ it.renderField("priority") }}</li>
{% endfor %}

render() draws the platform’s standard item link (type icon, #tag, title, open-in-new-window, side-panel click) — don’t hand-write that markup. Switch parts off with icon/tag/sidePanel/openInNewWindow.

{% for it in group.queryItems("completedDate:$empty") %}
  <li>{{ it.render() }}</li>
{% endfor %}

{{ group.queryItems("")[0].render(tag=false, openInNewWindow=false) }}

Transform text#

upper / lower / title / truncate are available as functions.

{% for it in group.queryItems("") %}
  <li>{{ upper(it.title) }} — {{ truncate(it.description, 80) }}</li>
{% endfor %}

Recent activity list#

A worked recipe: the five most recently updated open items, each linked with the standard item-link renderer and its update time formatted. Gonja’s slice filter splits a list into N chunks (the Jinja2 “columns” filter) rather than taking the first N — use Python-style subscripting (items[:5]) on a {% set %} variable instead.

{% set recent = group.queryItems("completedDate:$empty") | sort(attribute="updatedAt", reverse=true) %}
<div class="divide-y">
  {% for it in recent[:5] %}
    <div class="p-3">
      <div class="flex items-center justify-between">
        {{ it.render() }}
        <span class="text-xs text-gray-500">{{ date(it.updatedAt) }}</span>
      </div>
    </div>
  {% else %}
    <p class="p-4 text-gray-500">No recent activity</p>
  {% endfor %}
</div>

Status counts dashboard#

Group items by status once, then read each bucket’s count — avoids re-querying per status.

{% set byStatus = api.groupBy(group.queryItems(""), "status") %}
<div class="grid grid-cols-4 gap-4">
  {% for status in group.getStatuses(itemTypeId) %}
    <div class="p-4 rounded text-center">
      <div class="text-2xl font-bold">{{ byStatus[status.id] | default([]) | length }}</div>
      <div class="text-sm">{{ status.name }}</div>
    </div>
  {% endfor %}
</div>

Note

This last recipe assumes an itemTypeId widget parameter — see Scripted Widgets for how widget parameters reach the template.

See also#