> 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/acknowledging-a-privacy-notice.md).

# Acknowledging a Privacy Notice

When a form is filled in over several sittings, the moment that matters is not any individual answer but when somebody declares it finished. A status field offering Submit and Save for later gives you that moment, and a single Submit can confirm to the person who sent it, email several people depending on what they ticked, and copy their answers onto the compliance record.

This example is the privacy-notice counterpart to [Handling a Form Submission](/developer-documentation/case-scripting/on-save-scripts/examples/handling-a-form-submission.md), which covers the same shape on an insurance claim. Read both if you want to see how one pattern carries across sectors.

## The scenario

A data subject completes a privacy-notice acknowledgement. On Submit they receive a thank-you, the privacy team is emailed if they asked for a paper copy, opted out of optional cookies, or named a representative, and their answers are copied onto the compliance tab with a received date.

| Setting               | Value                                                                                                                     |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| Trigger field         | `5502` Acknowledgement status (`Submit` / `Save for later`)                                                               |
| Read on the form      | `5503` Paper copy requested, `5504` Optional cookies declined, `5505` Representative named, `5506` Representative details |
| Written to the record | `5507` Representative details (compliance tab), `5508` Acknowledgement received, `5509` Notice version accepted (date)    |
| Templates             | `PrivacyAck-DataSubject`, `PrivacyAck-PaperCopy`, `PrivacyAck-CookiesDeclined`, `PrivacyAck-Representative`               |

## The script

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

function on_save() {
    return true;
}

function after_save() {
    if (Changed.CustomField("5502").NewValueAsText != "Submit") {
        Service.AddMessage("Your answers have been saved. Remember to submit when you are ready.", "notify-info");
        return true;
    }

    var representative = Service.CustomField("5506").ValueAsText;

    Service.AddMessage(
        "Thank you for confirming you have read the privacy notice.\nWe have recorded your preferences.",
        "success");
    Service.SendEmail("PrivacyAck-DataSubject");

    if (Service.CustomField("5503").ValueAsText == "Yes") {
        Service.SendEmail("PrivacyAck-PaperCopy");
    }

    if (Service.CustomField("5504").ValueAsText == "Yes") {
        Service.SendEmail("PrivacyAck-CookiesDeclined");
    }

    if (Service.CustomField("5505").ValueAsText == "Yes") {
        Service.SendEmail("PrivacyAck-Representative");
        Service.UpdateCustomField("5507", representative);
    }

    var todayStamp = Service.GetCurrentDate().replace(/-/g, "");
    Service.UpdateCustomField("5508", "Yes");
    Service.UpdateCustomField("5509", todayStamp);

    return true;
}
```

## Save for later first

The script handles the case it is not interested in immediately and returns. That keeps the Submit logic unindented and makes it obvious what a partial save does: the answers are kept, nothing is sent, and the user is reminded to come back.

## Copying from the form onto the record

The representative's details live on the form tab in `5506` and need to appear on the compliance tab in `5507`. The script copies them across on Submit so the compliance record holds what was actually submitted, not what happened to be on the tab when somebody opened the case later.

The same pattern applies whenever a form collects answers that belong somewhere more permanent on the case. Copy on Submit, stamp a received flag, and use that flag if you need to prevent a second submission.

## Stamping the date

`Service.GetCurrentDate()` returns today as `yyyy-MM-dd`. Removing the hyphens gives `yyyyMMdd`, which is what many date fields expect when written from a script.

Using the service date rather than JavaScript's `Date` avoids the timezone edge case where `toISOString` names yesterday for a script that runs late in the evening.

## Submitting twice

The trigger only fires when the status changes, so choosing Submit again without an intervening change sends nothing. Moving to Save for later and back to Submit does fire again.

If that matters, gate on the received flag:

```javascript
if (Service.CustomField("5508").ValueAsText == "Yes") {
    Service.AddMessage("This acknowledgement has already been submitted.", "warn");
    return true;
}
```

Because `5508` is only set on a successful Submit, it is a reliable record that the work has already been done.


---

# 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/acknowledging-a-privacy-notice.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.
