Skip to content

Look Up a Record in Your Own System

An accounts payable reviewer works an invoice task and must know whether the vendor is active and approved in the vendor master, which lives in another system. This gizmo takes the vendor number from the work item, looks the vendor up in your own service, shows the status, and publishes it as task output so the workflow can route on it.

At a glance

  • Extension point Custom Gizmo calling your own HTTPS service
  • You need A vendor lookup service that allows Origin: null; an Index field with the vendor number; permissions Create Custom Gizmos and Manage Layouts
  • Teaches fetch from the sandbox, whitelist.txt, CORS, a timeout, and an error path the user can retry
Key Kind and meaning
vendor-number Input, string. The vendor number to look up.
vendor-status Result, string. approved, inactive, not-found or error.
vendor-name Result, string. The vendor name from your service, or empty.

Your service

The gizmo calls GET https://records.example.com/api/vendors/{number} and expects JSON like:

Response body
{ "number": "V-10422", "name": "Harbor Point Supply", "active": true, "approved": true }

The browser sends the request with Origin: null. Your service must return these headers on the response, and on an OPTIONS preflight if you add custom headers:

Response headers
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, OPTIONS

The request carries no cookie and no user identity. Return only data that any task user may see. See Security and Sandboxing.

Set it up

  1. Go to Configuration › Services › Custom Gizmos › New Custom Gizmo, title "Vendor Lookup". Paste the files below. Replace https://records.example.com with your service in whitelist.txt and main.js. Save.
  2. In the Tasks app, go to Layouts › Edit Layout › Add Gizmo › Custom Gizmo › "Vendor Lookup".
  3. In Configure Gizmo, on "Vendor number", tick Use Value from Input, Input Name vendor-number. Save the layout.
  4. In the Start A Task step, Input Mappings: map vendor-number to the Index field that holds the vendor number. With Task Scope "One Task per Document" you can map document metadata. With "One Task per Work Item", map work item metadata.
  5. Output Mappings: map vendor-status to the field the workflow routes on.

The files

index.html
<script src="{project}/main.js"></script>

<style>
    body { font-family: sans-serif; padding: 12px; }
    #status { font-size: 1.2em; font-weight: bold; margin: 8px 0; }
    .ok { color: #2e7d32; }
    .warn { color: #c62828; }
    button { margin-top: 8px; }
</style>

<div>Vendor <span id="number"></span></div>
<div id="name"></div>
<div id="status">Checking...</div>
<button type="button" id="retry" hidden>Try again</button>
main.js
// Vendor Lookup gizmo.
// Inputs:  vendor-number (string, mapped from the vendor number field).
// Results: vendor-status (approved, inactive, not-found, error), vendor-name.
// API permissions: none. Outside origins: https://records.example.com
var SERVICE = "https://records.example.com/api/vendors/";

gizmo.SetInputSchema(function (schema) {
    schema.AddString("vendor-number")
        .SetDisplayName("Vendor number")
        .SetExampleValue("V-10422")
        .ConfigureUI(function (ui) { ui.AsTextbox(); });
});

gizmo.OnReceiveConfig(function (config) {
});

gizmo.OnShow(function () {
    document.getElementById("retry").addEventListener("click", lookUp);
    lookUp();
});

function lookUp() {
    var number = (gizmo.Config.GetString("vendor-number", "") || "").trim();
    document.getElementById("number").textContent = number || "(none)";
    document.getElementById("retry").hidden = true;

    if (!number) {
        show("No vendor number on this work item.", "warn");
        publish("not-found", "");
        return;
    }

    show("Checking...", "");

    var controller = new AbortController();
    var timer = setTimeout(function () { controller.abort(); }, 10000);

    fetch(SERVICE + encodeURIComponent(number), { method: "GET", signal: controller.signal })
        .then(function (response) {
            clearTimeout(timer);
            if (response.status === 404) { return null; }
            if (!response.ok) { throw new Error("HTTP " + response.status); }
            return response.json();
        })
        .then(function (vendor) {
            if (vendor === null) {
                show("Vendor not found.", "warn");
                publish("not-found", "");
                return;
            }
            document.getElementById("name").textContent = vendor.name || "";
            if (vendor.active && vendor.approved) {
                show("Approved vendor", "ok");
                publish("approved", vendor.name || "");
            } else {
                show("Vendor is not active or not approved", "warn");
                publish("inactive", vendor.name || "");
            }
        })
        .catch(function (err) {
            clearTimeout(timer);
            console.error("Vendor lookup failed", err);
            show("Lookup failed. Check the service and try again.", "warn");
            document.getElementById("retry").hidden = false;
            publish("error", "");
        });
}

function show(text, cssClass) {
    var status = document.getElementById("status");
    status.textContent = text;
    status.className = cssClass;
}

function publish(status, name) {
    gizmo.Result
        .SetString("vendor-status", status)
        .SetString("vendor-name", name);
    gizmo.PublishResult();
}
whitelist.txt
// Vendor lookup service
https://records.example.com

How it works

  • The vendor number arrives as a task input. The gizmo has no other way to learn it.
  • fetch goes straight from the browser to your service. The CSP allows it only because the origin is in whitelist.txt.
  • An AbortController stops a request after 10 seconds, so a slow service cannot leave the reviewer waiting.
  • Every path publishes a status, including error, so the workflow can route a failed lookup to an exception queue.
  • A failed lookup shows Try again instead of failing silently.

Test it

  1. Open https://records.example.com/api/vendors/V-10422 in a browser to check that the service answers.
  2. Create a test task with vendor-number set to a known vendor number. Open it.
  3. Test an unknown number, then stop the service and test again to see the error path.
  4. In the browser developer tools, open the Network tab and check the request's Origin: null header and the response's Access-Control-Allow-Origin header.

You should see

"Approved vendor" in green for a known, approved vendor, "Vendor not found." for an unknown number, and Try again when the service is down.

What can go wrong

Watch out

  • Console: "Refused to connect ... violates the following Content Security Policy directive: connect-src". The origin is not in whitelist.txt, or it differs (http versus https, a missing subdomain).
  • Console: "has been blocked by CORS policy". Your service does not allow Origin: null. Add the headers above, including on OPTIONS.
  • The service needs a key. Do not put the key in main.js. Put a small service in front that holds the key and returns only what the gizmo needs.
  • The status is always not-found. The input is empty. Check the Input Mapping bucket and key in the Start A Task step.