> For the complete documentation index, see [llms.txt](https://docs.agilecase.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agilecase.com/developer-documentation/case-scripting.md).

# Case Scripting

<figure><img src="/files/nupn7HLidAhRRMnLoae7" alt="" width="186"><figcaption></figcaption></figure>

Case scripting lets you attach your own JavaScript to a case type, so that AgileCase runs your code at a particular moment. Scripts are created under **Scripting** in the settings menu, and each one is set to run either when a case is opened or when it is saved.

{% hint style="info" %}
If you want a script built but would rather not write it yourself, get in touch at <sales@agilecase.com> for information and pricing.
{% endhint %}

## The two kinds of script

<table data-view="cards"><thead><tr><th>Type</th><th>What it is for</th><th data-card-target data-type="content-ref">Target</th></tr></thead><tbody><tr><td><strong>On Load Scripts</strong></td><td>Run in the browser when a case is opened. Alter the case screen, surface buried data, warn the user.</td><td><a href="/pages/x1rVM9RDUIt06CF4q6Kg">/pages/x1rVM9RDUIt06CF4q6Kg</a></td></tr><tr><td><strong>On Save Scripts</strong></td><td>Run on the server when a case is saved. Send email, add tasks, update fields, call webhooks.</td><td><a href="/pages/EIVazrKMGqfbxU4VlQp5">/pages/EIVazrKMGqfbxU4VlQp5</a></td></tr></tbody></table>

The two run in completely different places, which is what decides how you write them. An on load script is ordinary browser JavaScript and reads case data through the [Case Data API](/developer-documentation/case-data-api.md). An on save script runs on the server with no access to the page, and acts on the case through the [Service object](/developer-documentation/case-scripting/on-save-scripts/script-api-reference.md).

{% hint style="warning" %}
Scripting for a single custom field tab is a separate feature. If you want a calculation or a formatting change confined to one tab, use a JavaScript label field instead, covered in [Custom Form Scripting](/developer-documentation/custom-form-scripting.md).
{% endhint %}

## Managing scripts

Creating, changing and removing scripts works the same way whichever type you choose.

<table data-view="cards"><thead><tr><th>Task</th><th>What it covers</th><th data-card-target data-type="content-ref">Target</th></tr></thead><tbody><tr><td><strong>Adding a New Script</strong></td><td>Naming a script, choosing when it runs, picking case types and writing the content.</td><td><a href="/pages/bMoLVNbRuBoQGwULYoqx">/pages/bMoLVNbRuBoQGwULYoqx</a></td></tr><tr><td><strong>Editing a Script</strong></td><td>Opening an existing script and changing it.</td><td><a href="/pages/kCOUgDxxHFUS8RXBpGj0">/pages/kCOUgDxxHFUS8RXBpGj0</a></td></tr><tr><td><strong>Deleting a Script</strong></td><td>Removing a script permanently.</td><td><a href="/pages/7l8YmuE9iZOG6eFsLLr2">/pages/7l8YmuE9iZOG6eFsLLr2</a></td></tr></tbody></table>

## Which case types a script applies to

Every script is attached to one or more case types when you create it, so a script written for one workflow does not affect another. A script with no case types selected never runs. This is set on the scripting form and can be changed later, as described in [Editing a Script](/developer-documentation/case-scripting/editing-a-script.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.agilecase.com/developer-documentation/case-scripting.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
