> 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/action-dropdown-that-resets-itself.md).

# An Action Dropdown That Resets Itself

Scripts are triggered by a field changing, which gives you a way to build something that behaves like a button. Add a dropdown whose options are actions rather than data, act on whichever one was chosen, then set the field back to its unanswered state. Because the field has changed again it is ready to be used a second time, and because it never holds a value for long it does not look like a record of anything.

This is the usual way to let a user re-send something on demand. Without the reset the dropdown would only ever work once, since choosing the same option again is not a change and would not trigger the script.

## The scenario

A privacy notice has been updated and needs circulating. Whoever is handling it chooses who should get the new version: the data subject, the internal privacy contact, or both.

| Setting       | Value                                                                                |
| ------------- | ------------------------------------------------------------------------------------ |
| Trigger field | `5501` Send updated privacy notice (dropdown)                                        |
| Options       | `Please Select`, `Data subject only`, `Staff contact only`, `Data subject and staff` |
| Templates     | `PrivacyNotice-DataSubject`, `PrivacyNotice-StaffContact`                            |

## The script

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

function after_save() {
    var action = Changed.CustomField("5501").NewValueAsText;

    if (action == "Data subject only") {
        Service.SendEmail("PrivacyNotice-DataSubject");
    } else if (action == "Staff contact only") {
        Service.SendEmail("PrivacyNotice-StaffContact");
    } else if (action == "Data subject and staff") {
        Service.SendEmail("PrivacyNotice-DataSubject");
        Service.SendEmail("PrivacyNotice-StaffContact");
    } else {
        return true;
    }

    Service.AddMessage("The updated privacy notice has been sent.", "notify-success");
    Service.UpdateCustomField("5501", "Please Select");
    return true;
}
```

## How it works

The early `return true` in the final branch is what makes the reset safe. When the script sets the field back to `Please Select` that is itself a change, so the script runs a second time with `Please Select` as the new value. That second run matches no action, returns immediately, and stops. Without it the script would reset the field, trigger itself, reset it again, and keep going.

Everything else follows from choosing `after_save`. Two emails can be queued from a single branch and both are sent, in the order you asked for them. The reset is queued alongside them and applied as part of the same batch of work.

{% hint style="warning" %}
Match your own field's unanswered option exactly. `Please Select` is the common default but the text is configurable, and if the value you write back does not exist in the dropdown the field is left showing something the user cannot re-select.
{% endhint %}

## Making it your own

The pattern extends to anything a user might want to trigger by hand rather than on a schedule: re-issuing a document, pushing a record to another system, or asking for a fresh AI review of an upload. Only the body of each branch changes.

If the action should be recorded rather than just performed, write the choice and the time to separate fields before clearing the dropdown. The dropdown stays a control, and the audit trail lives in fields that are not overwritten on the next use.


---

# 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/action-dropdown-that-resets-itself.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.
