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

# On Closing Document

> Cancel or allow document closing with the On Closing Document event, which runs in the FlexiCapture document editor before changes are confirmed.

## When it is launched

The script is launched when the document is being closed in the document editor (when going to a new document or closing the document editor) and prior to confirmation of changes.

* If the **CanClose.Value** property is set to **false**, the document will remain open.
* If the **CanClose.Value** property is set to **true**, the document will be closed after the script execution.

By default, the value of the **CanClose** parameter is **true**.

## Parameters

| **Name** | **Type**                                                                 | **Access** | **Description**                         |
| -------- | ------------------------------------------------------------------------ | ---------- | --------------------------------------- |
| CanClose | [IBoolean](/flexi-capture/appendix/scripts-shell/iboolean)               | Read/write | Specifies whether to close the document |
| Context  | [IDocumentEditor](/flexi-capture/appendix/scripts-shell/idocumenteditor) | Read/write | The document editor                     |
