Getting Started¶
This walkthrough builds a gizmo that greets a customer by name, places it in a task layout, feeds the name in from the work item, and sends a result back to the workflow. It takes about 20 minutes and touches every part of the gizmo contract once.
At a glance
- You build A "Greeting" gizmo with one input (
customer-name) and one result (greeting-status) - You need Permissions Create Custom Gizmos, Manage Layouts and Test Layouts, and a workflow with a Start A Task step
- You learn The editor, the input schema, aliasing an input, input and output mappings, and testing a task
graph TD
A["1. Create the project"] --> B["2 and 3. Write index.html and main.js"]
B --> C["4. Add it to a task layout"]
C --> D["5. Alias the input"]
D --> E["6. Map inputs and outputs in Start A Task"]
E --> F["7. Test the task"]
1. Create the project¶
- Go to Configuration › Services › Custom Gizmos.
- Select New Custom Gizmo and enter a title, for example "Greeting".
- The editor opens with five files:
index.html,main.js,whitelist.txt,gizmo.jsonandproject.json. A preview of the running gizmo shows next to the code.
gizmo.json and project.json are generated and read-only. See Project Structure. If you leave the editor with unsaved changes, it asks you to confirm.
2. Write index.html¶
Replace the template content:
<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">Greeting delivered</button>
{project}/ points at a file in this project. Paths that start with ./, / or {project}/ are all read as project files.
3. Write main.js¶
// 1. Declare the input this gizmo accepts.
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();
});
});
// 2. Required: OnShow waits for this callback.
gizmo.OnReceiveConfig(function (config) {
});
// 3. Start work when the gizmo is visible.
gizmo.OnShow(function () {
var name = gizmo.Config.GetString("customer-name", "World");
document.getElementById("greeting").textContent = "Hello, " + name + "!";
var button = document.getElementById("confirm");
button.disabled = gizmo.IsViewOnlyMode();
button.addEventListener("click", function () {
gizmo.Result.SetString("greeting-status", "delivered to " + name);
gizmo.PublishResult();
});
});
Save both files. When you save main.js, the editor runs the gizmo and writes the input schema and declared permissions into gizmo.json. Open gizmo.json to check that customer-name is there. The preview shows "Hello, World!" because the preview has no input.
4. Place it in a task layout¶
- Open the Tasks app and go to Layouts. Open a layout (or select Add a Layout) to reach Edit Layout.
- Select Add Gizmo in the ribbon, then Custom Gizmo.
- In Select Custom Gizmo, pick "Greeting". The dialog lists any Required Permissions the gizmo declares.
- Select the new gizmo on the page. The Configure Gizmo panel shows one row per schema key, here "Customer name".
The Develop Gizmo button in the ribbon opens the gizmo's code in a new tab.
5. Alias the input¶
In the "Customer name" row of Configure Gizmo:
- Tick Use Value from Input.
- Enter an Input Name, for example
customer-name. Periods are not allowed. - Save the layout.
The input now appears in the layout's inputs, next to the inputs every layout has (such as assign-to and task-name). Any task created from this layout can pass a value for it.
6. Connect the workflow¶
In the workflow designer, open the Start A Task step that uses this layout.
- Input Mappings Map the layout input
customer-nameto the metadata that holds the name (level, bucket and key). - Task Scope document-level mappings work only when Task Scope is "One Task per Document". With "One Task per Work Item", use work item metadata.
- Missing key In a "One Task per Work Item" task, a key that is not found is passed as literal text (the key name itself), so check the spelling.
- Output Mappings Map the output key
greeting-statusto the bucket and key where the workflow should store it.
When the user completes the task, the engine looks for each output key in the task results, including the results of every gizmo, and writes the first match to the mapped field.
7. Test the task¶
- In Edit Layout, save, then select the test button ("Create a Test Task").
- Enter a value for
customer-nameand select Create Task, then Open Task. - Open the browser developer tools (F12) and select Greeting delivered.
You should see
"Hello, Avery!" (or the name you entered) in the gizmo, and "Successfully published Gizmo result" in the browser console when you select the button. To test the full path, run a work item through the workflow and check the mapped output field after the task is completed.