TriggerBuilder

A generic builder for script triggers.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/script/trigger-builder#forDocument(Document)` | `https://developers.google.com/apps-script/reference/script/document-trigger-builder` | Creates and returns a `https://developers.google.com/apps-script/reference/script/document-trigger-builder` tied to the given document. |
| `https://developers.google.com/apps-script/reference/script/trigger-builder#forDocument(String)` | `https://developers.google.com/apps-script/reference/script/document-trigger-builder` | Creates and returns a `https://developers.google.com/apps-script/reference/script/document-trigger-builder` tied to the document with the given ID. |
| `https://developers.google.com/apps-script/reference/script/trigger-builder#forForm(Form)` | `https://developers.google.com/apps-script/reference/script/form-trigger-builder` | Creates and returns a `https://developers.google.com/apps-script/reference/script/form-trigger-builder` tied to the given form. |
| `https://developers.google.com/apps-script/reference/script/trigger-builder#forForm(String)` | `https://developers.google.com/apps-script/reference/script/form-trigger-builder` | Creates and returns a `https://developers.google.com/apps-script/reference/script/form-trigger-builder` tied to the form with the given ID. |
| `https://developers.google.com/apps-script/reference/script/trigger-builder#forSpreadsheet(Spreadsheet)` | `https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` | Creates and returns a `https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` tied to the given spreadsheet. |
| `https://developers.google.com/apps-script/reference/script/trigger-builder#forSpreadsheet(String)` | `https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` | Creates and returns a `https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` tied to the spreadsheet with the given ID. |
| `https://developers.google.com/apps-script/reference/script/trigger-builder#forUserCalendar(String)` | `https://developers.google.com/apps-script/reference/script/calendar-trigger-builder` | Returns a builder for building calendar triggers. |
| `https://developers.google.com/apps-script/reference/script/trigger-builder#timeBased()` | `https://developers.google.com/apps-script/reference/script/clock-trigger-builder` | Creates and returns a `https://developers.google.com/apps-script/reference/script/clock-trigger-builder` for building time-based triggers. |

## Detailed documentation

### `forDocument(document)`

Creates and returns a `https://developers.google.com/apps-script/reference/script/document-trigger-builder` tied to the given document.

```javascript
ScriptApp.newTrigger('myFunction')
    .forDocument(DocumentApp.getActiveDocument())
    .onOpen()
    .create();
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `document` | `https://developers.google.com/apps-script/reference/document/document.html` | The document. |

#### Return


`https://developers.google.com/apps-script/reference/script/document-trigger-builder` --- The new DocumentTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `forDocument(key)`

Creates and returns a `https://developers.google.com/apps-script/reference/script/document-trigger-builder` tied to the document with the given ID.

```javascript
ScriptApp.newTrigger('myFunction')
    .forDocument('1234567890abcdefghijklmnopqrstuvwxyz')
    .onOpen()
    .create();
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `key` | `String` | The ID for the document. |

#### Return


`https://developers.google.com/apps-script/reference/script/document-trigger-builder` --- The new DocumentTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`

*** ** * ** ***

### `forForm(form)`

Creates and returns a `https://developers.google.com/apps-script/reference/script/form-trigger-builder` tied to the given form.

```javascript
ScriptApp.newTrigger('myFunction')
    .forForm(FormApp.getActiveForm())
    .onFormSubmit()
    .create();
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `form` | `https://developers.google.com/apps-script/reference/forms/form.html` | The form. |

#### Return


`https://developers.google.com/apps-script/reference/script/form-trigger-builder` --- The new FormTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/forms.currentonly`
- `https://www.googleapis.com/auth/forms`

*** ** * ** ***

### `forForm(key)`

Creates and returns a `https://developers.google.com/apps-script/reference/script/form-trigger-builder` tied to the form with the given ID.

```javascript
ScriptApp.newTrigger('myFunction')
    .forForm('1234567890abcdefghijklmnopqrstuvwxyz')
    .onFormSubmit()
    .create();
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `key` | `String` | The ID for the form. |

#### Return


`https://developers.google.com/apps-script/reference/script/form-trigger-builder` --- The new FormTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/forms.currentonly`
- `https://www.googleapis.com/auth/forms`

*** ** * ** ***

### `forSpreadsheet(sheet)`

Creates and returns a `https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` tied to the given spreadsheet.

```javascript
ScriptApp.newTrigger('myFunction')
    .forSpreadsheet(SpreadsheetApp.getActive())
    .onEdit()
    .create();
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `sheet` | `https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet.html` | The spreadsheet. |

#### Return


`https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` --- The new SpreadsheetTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `forSpreadsheet(key)`

Creates and returns a `https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` tied to the spreadsheet with the given
ID.

```javascript
ScriptApp.newTrigger('myFunction')
    .forSpreadsheet('1234567890abcdefghijklmnopqrstuvwxyz')
    .onEdit()
    .create();
```

#### Parameters

| Name | Type | Description |
|---|---|---|
| `key` | `String` | The ID for the spreadsheet. |

#### Return


`https://developers.google.com/apps-script/reference/script/spreadsheet-trigger-builder` --- The new SpreadsheetTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/spreadsheets.currentonly`
- `https://www.googleapis.com/auth/spreadsheets`

*** ** * ** ***

### `forUserCalendar(emailId)`

Returns a builder for building calendar triggers.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `emailId` | `String` | Email ID of the user calendar the trigger monitors. |

#### Return


`https://developers.google.com/apps-script/reference/script/calendar-trigger-builder` --- The new CalendarTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/calendar`
- `https://www.googleapis.com/auth/calendar.readonly`
- `https://www.googleapis.com/auth/calendar.events`
- `https://www.googleapis.com/auth/calendar.events.readonly`
- `https://www.google.com/calendar/feeds`

*** ** * ** ***

### `timeBased()`

Creates and returns a `https://developers.google.com/apps-script/reference/script/clock-trigger-builder` for building time-based triggers.

```javascript
ScriptApp.newTrigger('myFunction').timeBased().atDate(2013, 10, 31).create();
```

#### Return


`https://developers.google.com/apps-script/reference/script/clock-trigger-builder` --- The new ClockTriggerBuilder.

#### Authorization

Scripts that use this method require authorization with one or more of the following [scopes](https://developers.google.com/apps-script/concepts/scopes#setting_explicit_scopes):

- `https://www.googleapis.com/auth/script.scriptapp`