Checklist That Blocks Task Completion¶
An accounts payable reviewer must confirm every item on a checklist ("Signature present", "Date present", "Amount matches the PO") before an invoice task can be completed. Today reviewers skip items under time pressure. This gizmo blocks the task until every box is ticked, and publishes which items were confirmed so the workflow keeps a record.
At a glance
- Extension point Custom Gizmo on the last page of a task layout
- You need Permissions Create Custom Gizmos and Manage Layouts; optional Output Mappings in the Start A Task step
- Teaches
BlockTaskandUnblockTask, a safeCheckIfCanProceed, a multi-line input, and a string-array result
| Key | Kind and meaning |
|---|---|
checklist-items |
Input, string. One checklist item per line. |
checklist-complete |
Result, string. "true" when every item is ticked, else "false". |
checklist-confirmed |
Result, string array. The items the reviewer ticked. |
Set it up¶
- Go to Configuration › Services › Custom Gizmos › New Custom Gizmo, title "Review Checklist". Paste the files below and save.
- In the Tasks app, go to Layouts › Edit Layout. Add the gizmo to the last page of the layout.
- In Configure Gizmo, type the checklist items in "Checklist items", one per line. To vary the list per work item, tick Use Value from Input instead and pass the list from the workflow.
- In the Start A Task step, add Output Mappings for
checklist-completeandchecklist-confirmedif the workflow needs them.
The files¶
index.html
<script src="{project}/main.js"></script>
<style>
body { font-family: sans-serif; padding: 12px; }
h3 { margin: 0 0 8px 0; }
label { display: block; padding: 6px 0; cursor: pointer; }
#summary { margin-top: 10px; font-weight: bold; }
.done { color: #2e7d32; }
.todo { color: #c62828; }
</style>
<h3>Review checklist</h3>
<div id="items"></div>
<div id="summary"></div>
main.js
// Review Checklist gizmo.
// Inputs: checklist-items (string, one item per line).
// Results: checklist-complete ("true" or "false"), checklist-confirmed (string array).
// API permissions: none. Outside origins: none.
var items = [];
var checked = {};
gizmo.SetInputSchema(function (schema) {
schema.AddString("checklist-items")
.SetDisplayName("Checklist items")
.SetDescription("One item per line")
.SetDefaultValue("Signature present\nDate present\nAmount matches the PO")
.ConfigureUI(function (ui) {
ui.AsTextbox().AllowMultipleLines().SetNumberOfLines(5);
});
});
gizmo.OnReceiveConfig(function (config) {
var raw = config.GetString("checklist-items", "");
items = raw.split(/\r?\n/)
.map(function (line) { return line.trim(); })
.filter(function (line) { return line.length > 0; });
});
gizmo.OnShow(function () {
var container = document.getElementById("items");
var readOnly = gizmo.IsViewOnlyMode();
container.textContent = "";
checked = {};
items.forEach(function (item, index) {
var label = document.createElement("label");
var box = document.createElement("input");
box.type = "checkbox";
box.disabled = readOnly;
box.addEventListener("change", function () {
checked[index] = box.checked;
update();
});
label.appendChild(box);
label.appendChild(document.createTextNode(" " + item));
container.appendChild(label);
});
if (!readOnly) {
update();
}
});
gizmo.CheckIfCanProceed(function () {
try {
return gizmo.IsViewOnlyMode() || allChecked();
} catch (e) {
console.error("Checklist check failed", e);
return false; // An error must not let the task through.
}
});
function allChecked() {
for (var i = 0; i < items.length; i++) {
if (!checked[i]) { return false; }
}
return true;
}
function update() {
var confirmed = items.filter(function (item, index) { return checked[index] === true; });
var complete = allChecked();
var summary = document.getElementById("summary");
summary.textContent = confirmed.length + " of " + items.length + " confirmed";
summary.className = complete ? "done" : "todo";
if (complete) {
gizmo.UnblockTask();
} else {
gizmo.BlockTask();
}
gizmo.Result
.SetString("checklist-complete", complete ? "true" : "false")
.SetStringArray("checklist-confirmed", confirmed);
gizmo.PublishResult();
}
How it works¶
OnReceiveConfigsplits the multi-line input into items. A blank line is skipped.OnShowdraws one checkbox per item and callsupdate(), which blocks the task until every box is ticked.- Each change republishes both results, so the workflow always gets the latest state.
CheckIfCanProceedis a second guard. It catches its own errors and returnsfalse, because an uncaught error would let the task proceed.- In view-only mode the boxes are disabled and the gizmo never blocks.
Test it¶
- Create a test task from the layout and open it.
- Go to the last page and try to complete the task.
- Tick every box, then complete the task. Check the mapped output fields after the workflow continues.
You should see
"A Gizmo is preventing your Task from being completed" while a box is unticked, a red "2 of 3 confirmed" summary that turns green at "3 of 3 confirmed", and the task completing once every box is ticked.
What can go wrong¶
Watch out
- The boxes are cleared when the user changes page. The gizmo reloads each time it is shown. That is why it belongs on the last page.
- The task can be completed with boxes unticked. The gizmo is not on the page the user completes from, or a change to
CheckIfCanProceedmoved code outside thetry. Keep the callback small, as above. - An empty list blocks nothing. With no items,
allChecked()returns true. Make sure the input has items.
Related¶
- API Reference:
BlockTask,CheckIfCanProceed - Hello World Gizmo
- Debugging Custom Gizmos