Skip to content

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

  1. Go to Configuration › Services › Custom Gizmos › New Custom Gizmo, title "Hello World".
  2. Replace index.html, main.js and whitelist.txt with the files below and save.
  3. In the Tasks app, go to Layouts › Edit Layout › Add Gizmo › Custom Gizmo and pick "Hello World".
  4. 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.";
            });
    });
});
whitelist.txt
// This gizmo calls no outside services.

How it works

  • SetInputSchema declares customer-name. Saving main.js writes it to gizmo.json, and the layout designer shows it as "Customer name".
  • OnReceiveConfig is empty but required: OnShow waits for it.
  • OnShow reads 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

  1. In Edit Layout, save, then create a test task. Enter Avery for customer-name, create the task and open it.
  2. Open the browser console (F12) and select Confirm greeting.
  3. To pass the result to the workflow, add an Output Mapping for greeting-status in 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...". OnShow did not run. Check that OnReceiveConfig is registered and that the console shows no error from main.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.json has no schema. Save main.js again with no errors, then remove and re-add the gizmo in the layout.