> ## Documentation Index
> Fetch the complete documentation index at: https://docs.insight.nobly.dk/llms.txt
> Use this file to discover all available pages before exploring further.

# Script examples you can adapt

> Use tested examples for Caseflow autofill, workflow decisions, and event acknowledgements, with explicit input and output contracts.

## Start with a contract, then a caller

These examples use only their input and return JSON-compatible dictionaries. Run them through the matching extension point in a test environment after [saving and publishing](/scripts/authoring-and-publishing). Creating a script does not connect it to a caller.

## Normalize a Caseflow reference

Choose **Caseflow Autofill** (`caseflow_autofill`). The caller supplies `trigger_value`; the result maps target attribute names to string values.

```python theme={null}
def execute(input, context):
    reference = input["trigger_value"].strip().upper()
    return {"values": {"CustomerReference": reference}}
```

| Input trigger value | Expected CustomerReference |
| ------------------- | -------------------------- |
| `  ab-1042  `       | `AB-1042`                  |
| `AB-1042`           | `AB-1042`                  |
| An empty string     | An empty string            |

Bind the published script to the intended Caseflow autofill target, and include `CustomerReference` among its allowed target attributes. Verify it in the consuming form. Decide separately whether an empty reference is acceptable; normalization does not enforce a required field.

## Return a workflow decision

Choose **Workflow Action** (`workflow_action`). Configure a **Script.Run** action to supply the input key `amount` and capture its output into an instance variable.

```python theme={null}
def execute(input, context):
    amount = input["amount"]
    if isinstance(amount, bool) or not isinstance(amount, (int, float)):
        raise ValueError("amount must be a number")
    if amount < 0:
        raise ValueError("amount must not be negative")
    return {"requires_review": amount >= 10000}
```

Test amounts `9999` and `10000`: the results are false and true respectively. Test a missing value, a string, a boolean, and a negative amount as rejected inputs. If your source keyword is text, convert it deliberately before passing it as a number.

Use the returned decision in a subsequent workflow condition. The script does not create a task or update a document by returning this value; those are separate configured actions. Script.Run resolves the published script by slug, so publishing a workflow does not freeze the script version.

## Acknowledge a document event

Choose **Event Hook** (`event_hook`). This minimal example verifies the event contract without writing to another system:

```python theme={null}
def execute(input, context):
    event_type = input["event_type"]
    entity_id = input["entity_id"]
    return {
        "acknowledged": True,
        "message": f"Received {event_type} for entity {entity_id}"
    }
```

For `event_type` equal to `document.created` and `entity_id` equal to `1042`, the message is `Received document.created for entity 1042`.

Publish it, then create a [binding](/scripts/bindings-and-events) for one test document type and the Document Created event. Create a representative document and inspect the script's execution log. An acknowledgement is not an upload, callback, or business-state change.

## Before adding an external integration

Replace the example behavior only after the caller, input, published version, and logs are working. Use `context["api"]` or `context["http"]` for the supported managed clients and `context["secrets"]` for configured credentials.

Define what happens after a timeout or duplicate event before adding a write operation. Keep an external operation idempotent where possible, and distinguish “request accepted” from “business operation completed.” Script-authoring access is trusted access because executed scripts can read the secrets supplied to their scope.

## Where to read next

<Card title="Bindings and event hooks" icon="code" href="/scripts/bindings-and-events" horizontal>
  Attach published scripts to external autofill sets, Caseflow forms, workflows, and document events.
</Card>
