Hello World Gizmo¶
The smallest complete gizmo. A service desk team wants a task to greet the customer by name and record that the greeting was confirmed. The gizmo takes one input, shows a greeting, and publishes one result when the user confirms. Copy it as the skeleton for every new gizmo.
At a glance
- Extension point Custom Gizmo in a task layout
- You need Permissions Create Custom Gizmos and Manage Layouts; a Start A Task step if you want the result in the workflow
- Teaches The gizmo skeleton (
SetInputSchema,OnReceiveConfig,OnShow), view-only handling, and publishing with success and failure feedback
| Key | Kind and meaning |
|---|---|
customer-name |
Input, string. The name to greet. Default "World". |
greeting-status |
Result, string. "confirmed" after the user selects the button. |
Set it up¶
- Go to Configuration › Services › Custom Gizmos › New Custom Gizmo, title "Hello World".
- Replace
index.html,main.jsandwhitelist.txtwith the files below and save. - In the Tasks app, go to Layouts › Edit Layout › Add Gizmo › Custom Gizmo and pick "Hello World".
- In Configure Gizmo, on "Customer name", tick Use Value from Input, Input Name
customer-name. Save the layout.
The files¶
index.html
<script src="{project}/main.js"></script>
<style>
body { font-family: sans-serif; padding: 12px; }
#greeting { font-size: 1.4em; margin-bottom: 12px; }
#status { color: #2e7d32; margin-top: 8px; }
</style>
<div id="greeting">Loading...</div>
<button type="button" id="confirm">Confirm greeting</button>
<div id="status"></div>
main.js
// Hello World gizmo.
// Inputs: customer-name (string; alias it with Use Value from Input).
// Results: greeting-status ("confirmed").
// API permissions: none. Outside origins: none.
gizmo.SetInputSchema(function (schema) {
schema.AddString("customer-name")
.SetDisplayName("Customer name")
.SetDescription("The name to greet")
.SetDefaultValue("World")
.SetExampleValue("Avery")
.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.";
});
});
});
How it works¶
SetInputSchemadeclarescustomer-name. Savingmain.jswrites it togizmo.json, and the layout designer shows it as "Customer name".OnReceiveConfigis empty but required:OnShowwaits for it.OnShowreads the input with a default, so the preview (which has no input) still shows "Hello, World!".- In view-only mode the button is disabled, so a user who has not taken the task cannot publish.
PublishResult()returns a Promise; the gizmo tells the user whether the save worked.
Test it¶
- In Edit Layout, save, then create a test task. Enter
Averyforcustomer-name, create the task and open it. - Open the browser console (F12) and select Confirm greeting.
- To pass the result to the workflow, add an Output Mapping for
greeting-statusin the Start A Task step.
You should see
"Hello, Avery!", then "Saved." under the button, and "Successfully published Gizmo result" in the console.
What can go wrong¶
Watch out
- The greeting stays on "Loading...".
OnShowdid not run. Check thatOnReceiveConfigis registered and that the console shows no error frommain.js. - The greeting says "Hello, World!" in the task. The input was not passed. Check Use Value from Input, the Input Name, and the test task value or the workflow Input Mapping.
- "Customer name" does not appear in Configure Gizmo.
gizmo.jsonhas no schema. Savemain.jsagain with no errors, then remove and re-add the gizmo in the layout.