> 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/on-save-scripts/examples/email-when-a-file-is-uploaded.md).

# Email When a File Is Uploaded

A file upload field triggers an on save script in the same way as a date or a dropdown. The script does not need to read the file itself; it only needs to know that the upload field changed, which is enough to notify somebody that a document has arrived.

## The scenario

An insurance handler uploads a loss adjuster's report to a claim. The claims handler should be told as soon as the file lands.

| Setting       | Value                                     |
| ------------- | ----------------------------------------- |
| Trigger field | `5301` Loss adjuster report (file upload) |
| Template      | `LossAdjusterReportUploaded-Handler`      |

## The script

```javascript
[Changed.CustomField(5301).Changed]

function on_save() {
    return true;
}

function after_save() {
    if (Changed.CustomField("5301").NewValueAsText === "") {
        return true;
    }

    Service.SendEmail("LossAdjusterReportUploaded-Handler");
    Service.AddMessage("The claims handler has been told the loss adjuster report was uploaded.", "notify-success");
    return true;
}
```

## Upload and removal

A new upload changes the field and triggers the script. Removing the file also changes it, so the empty check at the top prevents an email going out when somebody deletes the document.

If you need to distinguish replacement from first upload, compare old and new values as in [Reacting to Old and New Values](/developer-documentation/case-scripting/on-save-scripts/examples/reacting-to-old-and-new-values.md).

## Templates and attachments

The email template can include merge fields from the case and, depending on how the template is configured, may attach the uploaded document or link to it. The script does not pass the file in; it only names the template.

For work that inspects the document itself, such as an AI review, see [Running an AI Action on a Document](/developer-documentation/case-scripting/on-save-scripts/examples/running-an-ai-action-on-a-document.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/on-save-scripts/examples/email-when-a-file-is-uploaded.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.
