Introduction¶
A Custom Gizmo is a small web page (HTML, CSS and JavaScript) that you place in a task layout. A person working the task sees it next to the other gizmos, such as the Index Panel.
The gizmo:
- gets its inputs from the task;
- can call the KnowledgeLake API as the signed-in user;
- can call your own web services;
- publishes a result that becomes task output.
It is best for one job: giving a person in a task a screen the built-in gizmos do not have, such as a checklist, a lookup in your own system, or a picker fed by a live directory.
Custom Gizmos are available to every customer that has Tasks.
At a glance
- Runs In the user's browser, in a sandboxed iframe inside a task page
- Language HTML, CSS and JavaScript (any modern browser JavaScript)
- Authored in Configuration › Services › Custom Gizmos; placed with the Tasks app layout designer
- Can reach Its task inputs, the KnowledgeLake API through
gizmo.API(as the signed-in user), and origins listed inwhitelist.txt - Best for A custom screen for a person working a task, whose result feeds the workflow
Use a Custom Behavior instead when you only need to show, hide or validate Index fields. Use a Custom Step when no person is involved.
How a gizmo talks to the task¶
sequenceDiagram
participant T as Task page
participant G as Gizmo iframe
participant K as KnowledgeLake API
participant S as Your service
T->>G: Load index.html and project files
T->>G: Config from the layout and task inputs
T->>G: Show
G->>T: gizmo.API call
T->>K: Same call with the user session
K-->>T: Success, MessageKey, Data
T-->>G: Promise resolves
G->>S: fetch to a whitelisted origin with Origin null
S-->>G: JSON with CORS headers
G->>T: PublishResult
T->>T: Result becomes task output
The gizmo never holds a token. Every KnowledgeLake call goes through the task page, which checks that the group and action exist and then makes the call with the user's session.
Where you author it¶
| Task | Where and permission |
|---|---|
| Create, edit, import, export gizmos | Configuration › Services › Custom Gizmos ("Create Gizmos"). Permission: Create Custom Gizmos (customgizmos_ft_create_gizmos). |
| Place a gizmo in a task layout | Tasks app › Layouts › Edit Layout › Add Gizmo › Custom Gizmo. Permission: Manage Layouts. |
| Work a task that contains a gizmo | Tasks inbox. Permission: Use Custom Gizmos (customgizmos_ft_use_app), plus every API permission the gizmo declares. |
Runtime contract¶
| Item | Value |
|---|---|
| Engine | The user's browser. The gizmo runs in an iframe with sandbox="allow-scripts" inside the task page. |
| Runs when | Each time the gizmo is shown. The iframe is destroyed when the gizmo is hidden (for example on another task page) and loads fresh when it is shown again. |
| Timeout | No script timeout. The signed links that load project files expire after 5 minutes (tenant setting CustomGizmosHMACTimeoutInMinutes, default 5). |
| Network access | Only origins listed in whitelist.txt. Requests carry Origin: null, so the server must allow that in CORS. The KnowledgeLake API is reached only through gizmo.API. |
| Objects in scope | gizmo (also Gizmo), APIPermissions, and standard browser APIs. No cookies, localStorage, popups, alert, or form submission. |
| Data in | gizmo.Config: values set in the layout or passed in as task inputs |
| Data out | gizmo.Result plus gizmo.PublishResult() (task output), gizmo.Events, gizmo.BlockTask(), gizmo.CheckIfCanProceed() |
Rules¶
- Register
gizmo.OnReceiveConfig(...)whenever you usegizmo.OnShow(...).OnShowwaits for the config callback. - Start your work in
OnShow, not at the top ofmain.js. - Read inputs from
gizmo.Configonly after the config arrives. - Set values on
gizmo.Result, then callgizmo.PublishResult(). Publish again whenever the result changes. - Declare every API permission the gizmo uses with
gizmo.DeclarePermissions(...). - List every outside origin you call, and every outside script or image you load, in
whitelist.txt. - Put all code in files. Inline
<script>blocks and inline event handlers (onclick="...") are blocked. - Never put a secret (API key, password) in a gizmo file. Every user who opens the task can read it.
Gotchas¶
Mistakes that stop a gizmo, or let a task through
OnShownever fires. The gizmo has noOnReceiveConfigcallback, or that callback throws. Register one, even an empty one, and keep it short.- State is lost between pages. The gizmo reloads each time it is shown. Publish work as a result, or place the gizmo on the page where the user finishes.
CheckIfCanProceederrors let the task proceed. If your callback throws, the platform treats it astrue. Catch errors inside the callback and returnfalsewhen unsure.- Users cannot open the task. If a user lacks a permission the gizmo declares, the task page does not load: You are missing the "..." permission required by the ... Gizmo.
- External calls fail with a CORS error. The target server must answer requests that carry
Origin: null. See Security and Sandboxing. - A path that starts with
/means a project file.fetch("/api/...")is rewritten to a project file and fails. Usegizmo.APIfor KnowledgeLake and fullhttps://URLs for your own services.
Examples¶
- Hello World Gizmo: one input, one result, view-only handling.
- Checklist That Blocks Task Completion:
BlockTask,CheckIfCanProceedand a multi-line input. - Look Up a Record in Your Own System:
fetchto your own service,whitelist.txtand CORS. - Show Work Item Data with gizmo.API: pass the work item id in, read it as the signed-in user.
- Pick an Assignee from a Live Directory: your directory plus
V1_AppsAPI.GetUsers, then assign the next task. - Chart Task Values with a CDN Library: load a third-party library inside the sandbox.
Copy this into your assistant¶
Paste the block below into your AI assistant together with the AI Assistant Primer, then describe the gizmo you want. It is the same contract as this section, with a complete working project, written for a model.
# Custom Gizmo: context for AI assistants
You build a KnowledgeLake Custom Gizmo: a small web page (index.html, main.js, whitelist.txt) placed in a task layout. A person working the task sees it. It reads inputs from the task, can call the KnowledgeLake API as the signed-in user, can call outside services listed in whitelist.txt, and publishes a result that becomes task output. It runs only inside a task layout: never in a dashboard, a main menu or the Index app on its own.
## Runtime contract
- Runs in the user's browser, in an iframe with `sandbox="allow-scripts"` inside the task page.
- Loads fresh each time it is shown and is destroyed when hidden (another task page). In-memory state is lost.
- No cookies, no `localStorage` or `sessionStorage` (they throw), no `window.open`, no `alert` or `confirm`, no form submission, no access to the parent page.
- CSP: `connect-src`, `script-src`, `img-src`, `media-src` and `object-src` are `'self'` plus each line of whitelist.txt; `style-src-elem` adds `'unsafe-inline'`. So: no inline `<script>`, no `onclick=""`, no `eval` or `new Function`. Inline `<style>` and `style=""` are fine. `data:` images need `data:` in whitelist.txt.
- Every outside request carries `Origin: null`. The server must return `Access-Control-Allow-Origin: *` (or `null`) and answer `OPTIONS` preflights. No cookie or user identity reaches it.
- Project file links are signed and expire after 5 minutes. Load project assets at start.
- `console.log` works and shows in the browser console (F12).
## The objects
- `gizmo` (alias `Gizmo`): the only global you need.
- `gizmo.SetInputSchema(function (schema) { ... })`: `schema.AddString`, `AddStringArray`, `AddInt`, `AddLong`, `AddDecimal`, `AddBool`, `AddDateTime`, `AddByteArray(key)`, `AddPropertyBag(key)`. Chain `.SetDisplayName(text)`, `.SetDescription(text)`, `.SetDefaultValue(v)`, `.SetExampleValue(v)`, `.ConfigureUI(function (ui) { ui.AsTextbox(); })`. Other UI: `AsDropDown().AddOption(text, value)`, `AsCheckbox()`, `AsNumber()`, `AsCurrency()`, `AsDateTime()`, `AsRadioButtonGroup()`, `AsCheckBoxGroup()`; `AsTextbox().AllowMultipleLines().SetNumberOfLines(n)`.
- `gizmo.OnReceiveConfig(function (config) { ... })`: runs when inputs arrive. Always register it, even empty: `OnShow` waits for it.
- `gizmo.OnShow(function () { ... })`: runs when visible, after the config. Start work here.
- `gizmo.Config`: PropertyBag. `GetString(key, default)`, `GetBoolean`, `GetInt`, `GetLong`, `GetDecimal`, `GetDateTime`, `GetStringArray`. Typed: `GetString` does not see a value set as an int.
- `gizmo.Result`: PropertyBag. `SetString(key, value)` and the other setters; chainable.
- `gizmo.PublishResult()`: Promise. Sends the whole `Result`. Call again after each change.
- `gizmo.CheckIfCanProceed(function () { return true; })`: return a boolean or a Promise of one. A throw or rejection lets the task proceed.
- `gizmo.BlockTask()` and `gizmo.UnblockTask()`: hold or release the task. Unblocked on each load.
- `gizmo.IsViewOnlyMode()`: true for a read-only task. Disable input and do not block.
- `gizmo.DeclarePermissions(function (builder) { builder.AddPermission(APIPermissions.X); })`; also `AddPermissions([...])`.
- `gizmo.API.<Group>.<Action>(body)`: Promise of `{ Success, MessageKey, Data }`. Runs as the signed-in user. A failed call can reject or resolve with `Success: false`: handle both. Groups include V1_AppsAPI, V1_KWorkItemAPI, V1_BatchAPI, V1_RepositoryAPI, V1_WorkflowAPI, V1_ProcessingAPI, V1_JobsAPI, V1_RPAAPI, V1_AutomationAPI, V1_IntuitiveAIAPI, V1_TriggerAPI, V1_EventsAPI.
- `gizmo.Events.Publish(key, data)`, `Subscribe(key, fn)`, `Unsubscribe(key, fn)`: events between gizmos. A `'*'` subscriber sees `Key` as `'*'`.
- `APIPermissions`: constants such as `ManageWorkitems`, `CatalogsView`, `BatchRead`, `Repository`, `JobsGet`, `JobsManage`, `BotsGet`, `BotsManage`.
Common calls: `V1_KWorkItemAPI.GetWorkItem({ WorkItemId })` (ManageWorkitems) returns `{ WorkItemId, Name, Documents, Metadata }`; `V1_AppsAPI.GetCatalogs()` and `V1_AppsAPI.GetUsers({ CatalogId })` (CatalogsView) return users with `Token`, `DisplayName`, `Email`; `V1_ProcessingAPI.QueryForWorkItems({ WorkitemName })` (BatchRead).
Data reaches a gizmo only two ways: its config inputs and `gizmo.API`. It has no work item id of its own. To get one, declare an input (`work-item-id`), alias it in the layout (Use Value from Input), and map it in the Start A Task step: Level Batch, Bucket General, field Batch ID.
Task outputs: the Start A Task step's Output Mappings look up each output key across all gizmo results and take the first match. Use result keys no other gizmo on the layout uses.
Every layout has a built-in `assign-to` input. A user token mapped to it (for example a `Token` from `GetUsers`) assigns the new task to that user, if the user is in the task's assignment pool and may run the workflow.
## Rules
1. Register `OnReceiveConfig`. Read `gizmo.Config` in `OnShow`, never at the top level.
2. No inline script, no `on...=` attributes. Use `addEventListener` in main.js.
3. Paths starting with `/`, `./` or `{project}/` are rewritten to project files. Never `fetch("/api/...")`. Use `gizmo.API` for KnowledgeLake and full `https://` URLs for other services.
4. Declare every permission the API calls need. A user who lacks one cannot open the task page.
5. Task inputs arrive as text. Use `AddString` for aliased inputs and parse in code.
6. Wrap `CheckIfCanProceed` in `try`/`catch` and return `false` on error.
7. Never put a secret in a gizmo file. Treat calls to your own server as anonymous.
8. Place gizmos that collect work on the last page, or publish progress as results.
## Example: the hello-world project
index.html:
```html
<script src="{project}/main.js"></script>
<style>
body { font-family: sans-serif; padding: 12px; }
#greeting { font-size: 1.4em; margin-bottom: 12px; }
</style>
<div id="greeting">Loading...</div>
<button type="button" id="confirm">Confirm greeting</button>
<div id="status"></div>
```
main.js:
```javascript
// Inputs: customer-name (string, alias with Use Value from Input). Results: greeting-status.
gizmo.SetInputSchema(function (schema) {
schema.AddString("customer-name")
.SetDisplayName("Customer name")
.SetDefaultValue("World")
.ConfigureUI(function (ui) { ui.AsTextbox(); });
});
gizmo.OnReceiveConfig(function (config) {
// Nothing to prepare. OnShow needs this callback to exist.
});
gizmo.OnShow(function () {
var name = gizmo.Config.GetString("customer-name", "World");
var button = document.getElementById("confirm");
var status = document.getElementById("status");
document.getElementById("greeting").textContent = "Hello, " + name + "!";
button.disabled = gizmo.IsViewOnlyMode();
button.addEventListener("click", function () {
gizmo.Result.SetString("greeting-status", "confirmed");
gizmo.PublishResult()
.then(function () { status.textContent = "Saved."; })
.catch(function () { status.textContent = "Could not save. Try again."; });
});
});
```
whitelist.txt:
```text
// This gizmo calls no outside services.
```
## Output
Produce three files: index.html, main.js, whitelist.txt. Load scripts with `{project}/` paths. Start main.js with a comment block: the inputs (key, type, where the value comes from), the results (key, meaning), the API permissions, and the outside origins. Then give install steps: Configuration > Services > Custom Gizmos > New Custom Gizmo, paste the three files, save, check gizmo.json; Tasks app > Layouts > Edit Layout > Add Gizmo > Custom Gizmo; in Configure Gizmo tick Use Value from Input for each input; map inputs and outputs in the Start A Task step; create a test task and open it with the browser console open. If a field name, bucket, service URL or API action is not known, ask the user. Do not invent one.