Skip to content

SLA Elapsed Time Event

A claims operations lead has a service level: every claim must be indexed within 24 hours of arrival, and the target can change. The lead wants each claim's elapsed time, and whether it met the target, in the reporting database.

A Custom Step stamps the arrival time at the start of the workflow. A Custom Event step at the "indexed" milestone measures the time and records it against a target held in a global variable.

At a glance

  • Extension point Custom Event step, with a Custom Step at intake
  • You need A Secondary Event Provider with Custom ticked; a global variable SlaTargetHours (Decimal); permission to edit the workflow and to add global variables.
  • Teaches Date math in an event script, reading a global variable, and a computed true or false property.

Set it up

  1. In the Workflow app, open Global Variables and add SlaTargetHours, data type Generic Value, Decimal, value 24.
  2. In the Workflow designer, add a Custom Step as the first step of the claims workflow. Name it "Stamp Received Time". Paste the intake script below.
  3. Find the point you count as done, for example the route that leaves the indexing task when indexing is complete. Add a Custom Event step there. Name it "SLA Indexed Event".
  4. Set Scopes to sla, indexed.
  5. Paste the event script below into JavaScript Block. Save the steps and the workflow.

Script

Intake step

The intake step writes the arrival time once. If the work item comes back to the start, it keeps the first time.

Custom Step: Stamp Received Time
// Custom Step "Stamp Received Time". First step of the claims workflow.
// Writes work item General.ReceivedAt (ISO 8601, UTC) if it is not set yet.
var general = batch.Metadata["General"] || {};
if (!general["ReceivedAt"]) {
  builder.SetBatchMetadata("General", "ReceivedAt", new Date().toISOString());
}

Event step

Custom Event: SLA Indexed Event
// Custom Event "SLA Indexed Event". Scopes: sla, indexed
// Place where indexing counts as complete.
// Reads work item General.ReceivedAt and Index.ClaimNumber, global variable SlaTargetHours.
// Writes one event: custom, sla, indexed.
(function () {
  var general = batch.Metadata["General"] || {};
  var idx = batch.Metadata["Index"] || {};
  var target = parseFloat(GlobalVariables.Get("SlaTargetHours"));
  var received = new Date(general["ReceivedAt"] || "");
  var now = new Date();

  builder
    .SetEventProperty("claimNumber", idx["ClaimNumber"] || "")
    .SetEventProperty("milestone", "indexed")
    .SetEventProperty("measuredAt", now.toISOString())
    .SetEventProperty("slaTargetHours", isNaN(target) ? "" : String(target));

  if (isNaN(received.getTime())) {
    // No usable start time: record that, so the report can count it.
    builder
      .SetEventProperty("receivedAt", "")
      .SetEventProperty("elapsedHours", "")
      .SetEventProperty("slaMet", "unknown");
    return;
  }

  var hours = (now.getTime() - received.getTime()) / 3600000;

  builder
    .SetEventProperty("receivedAt", received.toISOString())
    .SetEventProperty("elapsedHours", hours.toFixed(2))
    .SetEventProperty("slaMet", isNaN(target) ? "unknown" : (hours <= target ? "true" : "false"));
})();

How it works

  • The intake Custom Step writes General.ReceivedAt at work-item level, in ISO 8601 UTC, so new Date(...) reads it the same way on every server.
  • The event script runs inside a function, so it can return early when the start time is missing.
  • GlobalVariables.Get("SlaTargetHours") returns text. parseFloat turns it into a number.
  • The work item reads the variable's version from when it was submitted, so a target change applies to new claims only.
  • elapsedHours is wall-clock time, with two decimals. slaMet is "true", "false" or "unknown", always a string.
  • The event carries WorkItemId and ProcessId, so a report can join it to the platform's own step events for a full timeline. See the Events Dictionary.

The event document

The event the report reads (ids shortened):

Event document
{
  "EventId": "0d93be41-...",
  "Scopes": ["custom", "sla", "indexed"],
  "Timestamp": "2026-10-07T16:42:05Z",
  "WorkItemId": "41c7aa10-...",
  "ProcessId": "9e2d6f38-...",
  "StepId": "b7a01c55-...",
  "WorkType": "Custom Event",
  "Properties": {
    "claimNumber": "CLM-448210",
    "milestone": "indexed",
    "measuredAt": "2026-10-07T16:42:05.118Z",
    "slaTargetHours": "24",
    "receivedAt": "2026-10-06T19:05:41.902Z",
    "elapsedHours": "21.61",
    "slaMet": "true"
  }
}

Report query

A Cosmos DB query for the share of claims that met the target:

Cosmos DB SQL: SLA met count
SELECT c.Properties.slaMet AS slaMet, COUNT(1) AS claims
FROM c
WHERE c.Scopes[0] = "custom" AND c.Scopes[1] = "sla" AND c.Scopes[2] = "indexed"
GROUP BY c.Properties.slaMet

Test it

  1. Run one claim through to the indexing milestone on a non-production tenant.
  2. In Monitor or Insight, check General.ReceivedAt on the work item.
  3. In your store, find the event by WorkItemId and scopes custom, sla, indexed.
  4. Set SlaTargetHours to 0.01, run a second claim, and check that its event has slaMet "false". Set the target back.

You should see

one event per claim, with elapsedHours equal to the time between receivedAt and measuredAt, and slaMet that matches the target in force when the claim was submitted.

What can go wrong

Watch out

  • The step fails with Global variable SlaTargetHours was not found. Create the variable before the first claim reaches the step. The name is case-sensitive.
  • slaMet is always "unknown". General.ReceivedAt is missing: the intake step is not on every path into the workflow, or it runs after this step. Put it first.
  • Elapsed times are hours off. A date was written without a time zone, such as 10/06/2026 2:05 PM. Write ISO 8601 with toISOString().
  • The target change did not apply. Claims already in flight keep the variable version from their submit time. Only new claims use the new target.
  • Business hours. This recipe measures wall-clock hours. If the contract counts business hours only, compute that in your report, where you have the calendar, rather than in the 10-second script.

Variations

  • Several milestones. Add a Custom Event step at each milestone with Scopes sla, classified, sla, indexed, sla, released. The same script works; change milestone.
  • Per-contract targets. Store a JSON global variable such as {"Standard": 24, "Priority": 4} and pick the target by Index.ContractType: JSON.parse(GlobalVariables.Get("SlaTargets"))[idx["ContractType"]].