### TextArea Configuration Example
Source: https://developers.google.com/apps-script/reference/data-studio/text-area
Example demonstrating how to create and configure a TextArea element using the Data Studio Community Connector API.
```APIDOC
## Usage
```javascript
const cc = DataStudioApp.createCommunityConnector();
const config = cc.getConfig();
const textArea1 = config.newTextArea()
.setId('textArea1')
.setName('Search')
.setHelpText('for example, Coldplay')
.setAllowOverride(true)
.setPlaceholder('Search for an artist for all songs.');
```
```
--------------------------------
### TextInput Configuration Example
Source: https://developers.google.com/apps-script/reference/data-studio/text-input
This example demonstrates how to create a TextInput element and configure its properties using the provided methods.
```APIDOC
## TextInput Configuration Example
This example demonstrates how to create a TextInput element and configure its properties using the provided methods.
```javascript
const cc = DataStudioApp.createCommunityConnector();
const config = cc.getConfig();
const info1 = config.newTextInput()
.setId('info1')
.setName('Search')
.setHelpText('for example, Coldplay')
.setAllowOverride(true)
.setPlaceholder('Search for an artist for all songs.');
```
```
--------------------------------
### SelectSingle Configuration Example
Source: https://developers.google.com/apps-script/reference/data-studio/select-single
This example demonstrates how to create a SelectSingle configuration object, add multiple options to it, and set various properties like ID, name, help text, and allow override.
```APIDOC
## SelectSingle Configuration
This example shows how to configure a `SelectSingle` element for Data Studio.
### Usage
```javascript
const cc = DataStudioApp.createCommunityConnector();
const config = cc.getConfig();
const option1 = config.newOptionBuilder().setLabel('option label').setValue('option_value');
const option2 = config.newOptionBuilder().setLabel('second option label').setValue('option_value_2');
const info1 = config.newSelectSingle()
.setId('api_endpoint')
.setName('Data Type')
.setHelpText('Select the data type you\'re interested in.')
.setAllowOverride(true)
.addOption(option1)
.addOption(option2);
```
### Methods
- `addOption(optionBuilder)`: Adds a new select option.
- `setAllowOverride(allowOverride)`: Enables overriding for this config entry.
- `setHelpText(helpText)`: Sets the help text for this configuration entry.
- `setId(id)`: Sets the unique ID for this configuration entry.
- `setIsDynamic(isDynamic)`: Sets the dynamic status for this configuration entry.
- `setName(name)`: Sets the display name for this configuration entry.
```
--------------------------------
### ActionResponse Examples
Source: https://developers.google.com/apps-script/reference/card-service/action-response
Examples of creating an ActionResponse to open a link, show a notification, or navigate to a new card.
```APIDOC
## ActionResponse Examples
### Description
Examples of creating an ActionResponse to open a link, show a notification, or navigate to a new card.
### Code Examples
```javascript
// An action that opens a link
const actionResponse = CardService.newActionResponseBuilder()
.setOpenLink(CardService.newOpenLink().setUrl('https://www.google.com'))
.build();
// An action that shows a notification.
const notificationActionResponse = CardService.newActionResponseBuilder()
.setNotification(
CardService.newNotification().setText(
'Some info to display to user'),
)
.build();
// An action that shows an additional card. It also sets a flag to indicate that
// the original state data has changed.
const cardBuilder = CardService.newCardBuilder();
// Build card ...
const navigationActionResponse = CardService.newActionResponseBuilder()
.setNavigation(CardService.newNavigation().pushCard(
cardBuilder.build()))
.setStateChanged(true)
.build();
```
```
--------------------------------
### Charts Service Example
Source: https://developers.google.com/apps-script/reference/charts/charts
This example demonstrates how to create a data table, build an area chart with it, and render it as an image on a web page.
```APIDOC
## doGet()
### Description
Creates a basic data table, populates an area chart with the data, and adds it into a web page as an image.
### Method
GET
### Endpoint
/
### Parameters
None
### Request Body
None
### Response
#### Success Response (200)
- **htmlOutput** (HtmlOutput) - The HTML content of the web page with the chart embedded.
### Response Example
```html
Render chart server side:
```
```
--------------------------------
### Create and Get Fields - Data Studio
Source: https://developers.google.com/apps-script/reference/data-studio/fields
Initializes a community connector and retrieves the fields object. Use this to start defining dimensions and metrics for your connector.
```javascript
const cc = DataStudioApp.createCommunityConnector();
const fields = cc.getFields();
const field1 = fields
.newDimension()
// Set other properties as needed.
.setId('field1_id');
```
--------------------------------
### setHostAppDataSource Example
Source: https://developers.google.com/apps-script/reference/card-service/date-time-picker
Example of using setHostAppDataSource to allow input variables to accept datetime outputs from other steps in a Google Workspace Studio agent.
```APIDOC
## setHostAppDataSource(hostAppDataSource)
In a Google Workspace Studio agent, lets input variables accept datetime outputs from other steps in the agent. For example, receive the time a gmail message was sent or the date on which a calendar event is scheduled. Only available for Google Workspace add-ons that extend Google Workspace Studio.
```javascript
const workflowDataSource = CardService.newWorkflowDataSource().setIncludeVariables(true);
const hostAppDataSource = CardService.newHostAppDataSource().setWorkflowDataSource(workflowDataSource);
const dateTimePicker = CardService.newDateTimePicker()
.setTitle('Enter the date and time.')
.setFieldName('date_time_field')
.setHostAppDataSource(hostAppDataSource);
```
```
--------------------------------
### `getTitle()`
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event-series
Gets the title of the event. Includes an example of how to retrieve and log the event title.
```APIDOC
## `getTitle()`
### Description
Gets the title of the event.
### Method
```javascript
// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById(
'abc123456@group.calendar.google.com',
);
// Gets the first event from the calendar for January 31st, 2023 that takes
// place between 9:05 AM and 9:15 AM. For an event series, use
// calendar.getEventSeriesById('abc123456@example.com'); and replace the series
// ID with your own.
const event = calendar.getEvents(
new Date('Jan 31, 2023 09:05:00'),
new Date('Jan 31, 2023 09:15:00'),
)[0];
if (event) {
// If an event exists within the given time frame, logs the title of the
// event.
console.log(event.getTitle());
} else {
// If no event exists within the given time frame, logs that information to
// the console.
console.log('No events exist for the specified range');
}
```
### Return
`String` — the title
### Authorization
Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API:
* `https://www.googleapis.com/auth/calendar`
* `https://www.googleapis.com/auth/calendar.readonly`
* `https://www.google.com/calendar/feeds`
```
--------------------------------
### getOwner()
Source: https://developers.google.com/apps-script/reference/drive/folder
Gets the owner of this Folder. Includes an example of how to retrieve and log the owner's name.
```APIDOC
## getOwner()
### Description
Gets the owner of this `Folder`.
### Request Example
```javascript
// Gets a folder by its ID.
// TODO(developer): Replace the folder ID with your own.
const folder = DriveApp.getFolderById('1234567890abcdefghijklmnopqrstuvwxyz');
// Gets the owner of the folder and logs the name to the console.
const folderOwner = folder.getOwner();
console.log(folderOwner.getName());
```
### Return
`User` — The owner of this `Folder`.
### Authorization
Scripts that use this method require authorization with one or more of the following scopes:
* `https://www.googleapis.com/auth/drive.readonly`
* `https://www.googleapis.com/auth/drive`
```
--------------------------------
### getActiveUserLocale()
Source: https://developers.google.com/apps-script/reference/base/session
Gets the language setting of the current user as a string—for example, `en` for English.
```APIDOC
## getActiveUserLocale()
### Description
Gets the language setting of the current user as a string—for example, `en` for English.
### Method
`Session.getActiveUserLocale()`
### Return
`String` — a string that represents the user's language setting
### Request Example
```javascript
// Log the language setting of the person running the script.
Logger.log(Session.getActiveUserLocale());
```
```
--------------------------------
### LinkPreview Class Overview
Source: https://developers.google.com/apps-script/reference/card-service/link-preview
This example demonstrates how to build and return a LinkPreview object, which includes setting a preview card and a title for the smart chip.
```APIDOC
## LinkPreview
Card action that displays a link preview card and smart chip in the host app. To use link previews, you must build and return a `LinkPreview` object in your script. For more information, refer to Preview links with smart chips.
```javascript
const decoratedText = CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');
const cardSection = CardService.newCardSection().addWidget(decoratedText);
const card = CardService.newCardBuilder().addSection(cardSection).build();
return CardService.newLinkPreview().setPreviewCard(card).setTitle('Smart chip title');
```
```
--------------------------------
### Get Calendar Event Start Time
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event
Retrieves the start time of a specific calendar event. This method is useful for determining when an event begins, whether it's a timed event or an all-day event.
```javascript
const calendar = CalendarApp.getCalendarById(
'abc123456@group.calendar.google.com',
);
const event = calendar.getEvents(
new Date('Feb 01, 2023 16:10:00'),
new Date('Feb 01, 2023 16:25:00'),
)[0];
const startTime = event.getStartTime();
console.log(startTime);
```
--------------------------------
### Create Video Entry Point
Source: https://developers.google.com/apps-script/reference/conference-data/entry-point
Creates a new EntryPoint object configured for video conferencing. Sets the type to VIDEO, provides a sample URI, and a passcode.
```javascript
const videoEntryPoint = ConferenceDataService.newEntryPoint()
.setEntryPointType(ConferenceDataService.EntryPointType.VIDEO)
.setUri('https://example.com/myroom')
.setPasscode('12345');
```
--------------------------------
### Get the start date of an all-day event
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event
Retrieves the start date for an all-day event. This method throws an error if the event is not an all-day event. The returned date is in the script's time zone.
```javascript
const calendar = CalendarApp.getDefaultCalendar();
const event = calendar.createAllDayEvent(
'My all-day event',
new Date('May 16, 2023'),
);
const startDate = event.getAllDayStartDate();
console.log(startDate);
```
--------------------------------
### getLowerBound()
Source: https://developers.google.com/apps-script/reference/forms/scale-item
Gets the minimum value of the scale. This defines the starting point of the numerical scale presented to the respondent.
```APIDOC
## getLowerBound()
### Description
Gets the scale's lower bound.
### Method
Not applicable (App Script method)
### Return
`Integer` — the scale's lower bound
### Authorization
Scripts that use this method require authorization with one or more of the following scopes:
* `https://www.googleapis.com/auth/forms.currentonly`
* `https://www.googleapis.com/auth/forms`
```
--------------------------------
### Sample Usage of ReturnOutputVariablesAction
Source: https://developers.google.com/apps-script/reference/add-ons-response-service/return-output-variables-action
Demonstrates how to create and configure a ReturnOutputVariablesAction, including setting variable data and integrating it into a HostAppAction and RenderAction.
```javascript
const variableDataMap = {
"result": AddOnsResponseService.newVariableData()
.addIntegerValue(100)
};
const workflowAction = AddOnsResponseService.newReturnOutputVariablesAction()
.setVariableDataMap(variableDataMap);
const hostAppAction = AddOnsResponseService.newHostAppAction()
.setWorkflowAction(workflowAction);
const renderAction = AddOnsResponseService.newRenderActionBuilder()
.setHostAppAction(hostAppAction)
.build();
return renderAction;
```
--------------------------------
### `getVisibility()`
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event-series
Gets the visibility of the event. Includes an example demonstrating how to retrieve and log the event's visibility.
```APIDOC
## `getVisibility()`
### Description
Gets the visibility of the event.
### Method
```javascript
// Opens the calendar by its ID. You must have edit access to the calendar.
// TODO(developer): Replace the ID with your own.
const calendar = CalendarApp.getCalendarById(
'abc123456@group.calendar.google.com',
);
// Gets the first event from the calendar for February 1st, 2023 that takes
// place between 4:10 PM and 4:25 PM. For an event series, use
// calendar.getEventSeriesById('abc123456@google.com'); and replace the series
// ID with your own.
const event = calendar.getEvents(
new Date('Feb 01, 2023 16:10:00'),
new Date('Feb 01, 2023 16:25:00'),
)[0];
if (event) {
// If an event exists within the given time frame, gets the visibility of the
// event and logs it.
const eventVisibility = event.getVisibility();
console.log(eventVisibility.toString());
} else {
// If no event exists within the given time frame, logs that information to
// the console.
console.log('No events exist for the specified range');
}
```
### Return
`Visibility` — the visibility value
### Authorization
Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API:
* `https://www.googleapis.com/auth/calendar`
* `https://www.googleapis.com/auth/calendar.readonly`
* `https://www.google.com/calendar/feeds`
```
--------------------------------
### Create a Link Preview
Source: https://developers.google.com/apps-script/reference/card-service/card-service
Shows how to create a LinkPreview object with a custom card and title.
```Apps Script
const decoratedText =
CardService.newDecoratedText().setTopLabel('Hello').setText('Hi!');
const cardSection = CardService.newCardSection().addWidget(decoratedText);
const card = CardService.newCardBuilder().addSection(cardSection).build();
return CardService.newLinkPreview().setPreviewCard(card).setTitle(
'Smart chip title');
```
--------------------------------
### Example Usage
Source: https://developers.google.com/apps-script/reference/charts/area-chart-builder
Demonstrates how to create and configure an area chart using the AreaChartBuilder.
```javascript
// Create a data table with some sample data.
const sampleData = Charts.newDataTable()
.addColumn(Charts.ColumnType.STRING, 'Month')
.addColumn(Charts.ColumnType.NUMBER, 'Dining')
.addColumn(Charts.ColumnType.NUMBER, 'Total')
.addRow(['Jan', 60, 520])
.addRow(['Feb', 50, 430])
.addRow(['Mar', 53, 440])
.addRow(['Apr', 70, 410])
.addRow(['May', 80, 390])
.addRow(['Jun', 60, 500])
.addRow(['Jul', 100, 450])
.addRow(['Aug', 140, 431])
.addRow(['Sep', 75, 488])
.addRow(['Oct', 70, 521])
.addRow(['Nov', 58, 388])
.addRow(['Dec', 63, 400])
.build();
const chart = Charts.newAreaChart()
.setTitle('Yearly Spending')
.setXAxisTitle('Month')
.setYAxisTitle('Spending (USD)')
.setDimensions(600, 500)
.setStacked()
.setColors(['red', 'green'])
.setDataTable(sampleData)
.build();
```
--------------------------------
### GmailLabel.getThreads(start, max)
Source: https://developers.google.com/apps-script/reference/gmail/gmail-label
Gets a range of threads marked with this label. This method requires the 'https://mail.google.com/' scope for authorization.
```APIDOC
## getThreads(start, max)
### Description
Gets a range of threads marked with this label.
### Method
`getThreads(start, max)`
### Parameters
#### Path Parameters
- **start** (Integer) - Required - The starting index of the threads to retrieve.
- **max** (Integer) - Required - The maximum number of threads to retrieve.
### Response
#### Success Response (200)
- **GmailThread[]** - An array of Gmail threads marked with this label within the specified range.
### Authorization
Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API:
* `https://mail.google.com/`
```
--------------------------------
### Serve 'Hello World' text content
Source: https://developers.google.com/apps-script/reference/content/content-service
Use this snippet to publish a script as a web app that returns simple text content. The browser will display the text from a different URL than the script's original URL.
```javascript
function doGet() {
return ContentService.createTextOutput('Hello World');
}
```
--------------------------------
### getStartTime()
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event
Gets the date and time at which this calendar event begins. For non–all-day events, this is the instant in time at which the event was defined to start. For all-day events, this is midnight at the beginning of the day on which the event starts in the calendar's time zone.
```APIDOC
## getStartTime()
### Description
Gets the date and time at which this calendar event begins.
### Return
`Date` — this calendar event's start time
```
--------------------------------
### getThreads(start, max)
Source: https://developers.google.com/apps-script/reference/gmail/gmail-label
Gets a specified range of threads marked with this label. This is useful for handling large numbers of threads efficiently.
```APIDOC
## getThreads(start, max)
### Description
Gets a range of threads marked with this label. This method allows for paginated retrieval of threads, which is recommended when dealing with a large number of threads to avoid system limitations.
### Method
`getThreads(start, max)`
### Parameters
#### Path Parameters
- **start** (`Integer`) - Required - The index of the starting thread.
- **max** (`Integer`) - Required - The maximum number of threads to return.
### Return
`GmailThread[]` - An array of threads marked with this label within the specified range.
### Authorization
Scripts that use this method require authorization with the following scope:
* `https://mail.google.com/`
### Example
```javascript
// log the subject lines of up to the first 30 threads with the label MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
const threads = label.getThreads(0, 30);
for (let i = 0; i < threads.length; i++) {
Logger.log(threads[i].getFirstMessageSubject());
}
```
```
--------------------------------
### Get the creation date of a calendar event
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event-series
Use `getDateCreated()` to get the date an event was created. You must have access to the calendar. This example demonstrates fetching an event within a specific time range and logging its creation date. Requires the `calendar` scope.
```javascript
const calendar = CalendarApp.getCalendarById('abc123456@group.calendar.google.com');
const event = calendar.getEvents(new Date('Feb 01, 2023 08:10:00'), new Date('Feb 01, 2023 16:25:00'))[0];
if (event) {
const eventCreated = event.getDateCreated();
console.log(eventCreated);
} else {
console.log('No events exist for the specified range');
}
```
--------------------------------
### setUpdateType
Source: https://developers.google.com/apps-script/reference/add-ons-response-service/update-draft-body-action
Sets the UpdateDraftBodyType of this update action on the draft body. For example, inserting content at the start, end, or cursor position of the draft body.
```APIDOC
## setUpdateType(updateType)
### Description
Sets the `UpdateDraftBodyType` of this update action on the draft body. For example, inserting content at the start, end, or cursor position of the draft body.
### Parameters
#### Path Parameters
- None
#### Query Parameters
- None
#### Request Body
- **updateType** (UpdateDraftBodyType) - Required - The type of update to be performed on an email draft.
### Request Example
```json
{
"updateType": ""
}
```
### Response
#### Success Response (200)
- **UpdateDraftBodyAction** - This object, for chaining.
#### Response Example
```json
{
"message": "UpdateDraftBodyAction object returned for chaining"
}
```
```
--------------------------------
### Create and Configure an Info Object
Source: https://developers.google.com/apps-script/reference/data-studio/info
This snippet demonstrates how to create a new Info object and set its ID and text. Use this to provide context within your Data Studio configuration.
```javascript
const cc = DataStudioApp.createCommunityConnector();
const config = cc.getConfig();
const info1 = config.newInfo().setId('info1').setText(
'This text gives some context on the configuration.');
```
--------------------------------
### `getTransparency()`
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event-series
Gets the transparency of the event, determining if the calendar shows as Available or Busy during that time. Includes an example of logging the event's transparency.
```APIDOC
## `getTransparency()`
### Description
Gets the transparency of the event. Use this method to determine whether an event is ` TRANSPARENT`, meaning the calendar shows as Available during that time, or `OPAQUE `, meaning the calendar shows as Busy during that time.
### Method
```javascript
// Gets the first event from the default calendar for today.
const today = new Date();
const event = CalendarApp.getDefaultCalendar().getEventsForDay(today)[0];
// Gets the event's transparency and logs it.
const transparency = event.getTransparency();
Logger.log(transparency);
```
### Return
`EventTransparency` — The transparency value.
### Authorization
Scripts that use this method require authorization with one or more of the following scopes or appropriate scopes from the related REST API:
* `https://www.googleapis.com/auth/calendar`
* `https://www.googleapis.com/auth/calendar.readonly`
* `https://www.google.com/calendar/feeds`
```
--------------------------------
### getHelpText()
Source: https://developers.google.com/apps-script/reference/forms/checkbox-grid-item
Gets the item's help text. Returns the item's help text or description text.
```APIDOC
## getHelpText()
### Description
Gets the item's help text (sometimes called description text for layout items like `ImageItems`, `PageBreakItems`, and `SectionHeaderItems`).
### Return
`String` — the item's help text or description text
### Authorization
Scripts that use this method require authorization with one or more of the following scopes:
* `https://www.googleapis.com/auth/forms.currentonly`
* `https://www.googleapis.com/auth/forms`
```
--------------------------------
### Create and Configure a ResourceField
Source: https://developers.google.com/apps-script/reference/add-ons-response-service/resource-field
Demonstrates how to create a new ResourceField, set its selector, display text, and data type using the AddOnsResponseService. This is typically done within an `onDynamicDefinitionFunction`.
```javascript
function onDynamicDefinitionFunction(e) {
// ...
let resourceField = AddOnsResponseService.newResourceField()
.setSelector("question_1")
.setDisplayText("Question 1")
.setDataType(AddOnsResponseService.newDataType()
.setBasicDataType(AddOnsResponseService.BasicDataType.STRING)
);
let resourceDefinitions = AddOnsResponseService.newDynamicResourceDefinition()
.setResourceId("resource_definition_1")
.addResourceField(resourceField);
// ...
}
```
--------------------------------
### getNumRows()
Source: https://developers.google.com/apps-script/reference/document/table
Retrieves the number of table rows in a table. Includes an example of getting the number of rows from the first table in a document. Requires Google Docs scopes.
```APIDOC
## getNumRows()
### Description
Retrieves the number of `TableRows`.
### Return
- **Integer** - The number of table rows.
### Authorization
Scripts that use this method require authorization with one or more of the following scopes:
- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`
### Example
```javascript
// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('123abc');
// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab('123abc').asDocumentTab().getBody();
// Gets the first table.
const table = body.getTables()[0];
// Logs the number of rows of the first table to the console.
console.log(table.getNumRows());
```
```
--------------------------------
### Create SIP Entry Point
Source: https://developers.google.com/apps-script/reference/conference-data/entry-point
Creates a new EntryPoint object for SIP conferencing. Sets the type to SIP and provides a sample SIP URI and access code.
```javascript
const sipEntryPoint = ConferenceDataService.newEntryPoint()
.setEntryPointType(ConferenceDataService.EntryPointType.SIP)
.setUri('sip:joe@example.com')
.setAccessCode('1234567');
```
--------------------------------
### getThreads()
Source: https://developers.google.com/apps-script/reference/gmail/gmail-label
Gets all threads that are marked with this label. Be cautious with large numbers of threads as this can cause system issues. Consider using `getThreads(start, max)` for paginated retrieval.
```APIDOC
## getThreads()
### Description
Gets the threads that are marked with this label. This method may fail if the total number of threads associated with the label is too large to be handled by the system. For potentially very large sets of threads, use `getThreads(start, max)` to retrieve threads in ranges.
### Method
`getThreads()`
### Return
`GmailThread[]` - An array of threads marked with this label.
### Authorization
Scripts that use this method require authorization with the following scope:
* `https://mail.google.com/`
### Example
```javascript
// Log the subject lines of the threads labeled with MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
const threads = label.getThreads();
for (let i = 0; i < threads.length; i++) {
Logger.log(threads[i].getFirstMessageSubject());
}
```
```
--------------------------------
### Column Class Overview
Source: https://developers.google.com/apps-script/reference/card-service/column
Demonstrates the creation and basic configuration of a Column object, including setting size, alignment, and adding a widget.
```APIDOC
## Column Class
A column.
Available for Google Chat apps and Google Workspace add-ons.
```javascript
const columnWidget = CardService.newTextParagraph();
const column =
CardService.newColumn()
.setHorizontalSizeStyle(
CardService.HorizontalSizeStyle.FILL_AVAILABLE_SPACE)
.setHorizontalAlignment(CardService.HorizontalAlignment.CENTER)
.setVerticalAlignment(CardService.VerticalAlignment.CENTER)
.addWidget(columnWidget);
```
```
--------------------------------
### getColumnWidth(columnIndex)
Source: https://developers.google.com/apps-script/reference/document/table
Retrieves the width of the specified table column, in points. Includes an example of setting and getting column width. Requires Google Docs scopes for authorization.
```APIDOC
## getColumnWidth(columnIndex)
### Description
Retrieves the width of the specified table column, in points.
### Parameters
- **columnIndex** (Integer) - The column index.
### Return
- **Number|null** - The column width, in points.
### Authorization
Scripts that use this method require authorization with one or more of the following scopes:
- `https://www.googleapis.com/auth/documents.currentonly`
- `https://www.googleapis.com/auth/documents`
### Example
```javascript
// Opens the Docs file by its ID. If you created your script from within a
// Google Docs file, you can use DocumentApp.getActiveDocument() instead.
// TODO(developer): Replace the ID with your own.
const doc = DocumentApp.openById('123abc');
// Gets the body contents of the tab by its ID.
// TODO(developer): Replace the ID with your own.
const body = doc.getTab('123abc').asDocumentTab().getBody();
// Gets the first table.
const table = body.getTables()[0];
// Sets the width of the second column to 100 points.
const columnWidth = table.setColumnWidth(1, 100);
// Gets the width of the second column and logs it to the console.
console.log(columnWidth.getColumnWidth(1));
```
```
--------------------------------
### Open and Create Google Documents
Source: https://developers.google.com/apps-script/reference/document/document-app
Examples of opening an existing document by ID and creating a new document with a specified name.
```javascript
// Open a document by ID.
// TODO(developer): Replace the ID with your own.
let doc = DocumentApp.openById('DOCUMENT_ID');
// Create and open a document.
doc = DocumentApp.create('Document Name');
```
--------------------------------
### Add and Get Pop-up Reminders for an Event
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event-series
Adds pop-up reminders to an event and then retrieves all set pop-up reminder values. Reminders are specified in minutes before the event starts.
```javascript
const calendar = CalendarApp.getCalendarById(
'abc123456@group.calendar.google.com',
);
const event = calendar.getEvents(
new Date('Feb 04, 2023 17:05:00'),
new Date('Feb 04, 2023 17:35:00'),
)[0];
if (event) {
event.addPopupReminder(3);
event.addPopupReminder(5);
const popUpReminder = event.getPopupReminders();
console.log(popUpReminder);
} else {
console.log('No events exist for the specified range');
}
```
--------------------------------
### Checkbox Configuration Example
Source: https://developers.google.com/apps-script/reference/data-studio/checkbox
Demonstrates how to create and configure a Checkbox object using the Data Studio API. This includes setting the ID, display name, help text, and override capability.
```APIDOC
## Checkbox Configuration Example
### Description
This example shows how to instantiate a Checkbox and configure its properties like ID, name, help text, and allow override.
### Method
`newCheckbox()` followed by chaining setter methods.
### Endpoint
N/A (Client-side scripting)
### Parameters
N/A for the overall example, but individual methods have parameters:
- `setId(id)`: Sets the unique ID for the checkbox.
- `setName(name)`: Sets the display name for the checkbox.
- `setHelpText(helpText)`: Sets the help text that appears for the checkbox.
- `setAllowOverride(allowOverride)`: Enables or disables overriding the checkbox setting in reports.
### Request Example
```javascript
const config = DataStudioApp.createCommunityConnector().getConfig();
const checkbox = config.newCheckbox()
.setId('use_https')
.setName('Use Https?')
.setHelpText('Whether or not https should be used.')
.setAllowOverride(true);
```
### Response
Returns the `Checkbox` builder object for further chaining.
```
--------------------------------
### DateTimePicker Usage Example
Source: https://developers.google.com/apps-script/reference/card-service/date-time-picker
Demonstrates how to create and configure a DateTimePicker, including setting a title, field name, default value, time zone offset, and an on-change action.
```APIDOC
## DateTimePicker
An input field that allows users to input a date and time. Supports form submission validation.
```javascript
const dateTimePicker = CardService.newDateTimePicker()
.setTitle('Enter the date and time.')
.setFieldName('date_time_field')
// Set default value as Jan 1, 2018, 3:00 AM UTC. Either a number or
// string is acceptable.
.setValueInMsSinceEpoch(1514775600)
// EDT time is 5 hours behind UTC.
.setTimeZoneOffsetInMins(-5 * 60)
.setOnChangeAction(CardService.newAction().setFunctionName('handleDateTimeChange'));
```
```
--------------------------------
### Get Events in a Time Range
Source: https://developers.google.com/apps-script/reference/calendar/calendar
Retrieves events that start, end, or encompass a specified time range. The time is interpreted in the script's time zone if not specified.
```javascript
// Determines how many events are happening in the next two hours.
const now = new Date();
const twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);
const events = CalendarApp.getDefaultCalendar().getEvents(now, twoHoursFromNow);
Logger.log(`Number of events: ${events.length}`);
```
--------------------------------
### Creating Navigation
Source: https://developers.google.com/apps-script/reference/add-ons-response-service
Use `newNavigation()` to create a new `Navigation` instance.
```APIDOC
## newNavigation()
### Description
Creates a `Navigation`.
### Returns
- `Navigation` - A new instance of `Navigation`.
```
--------------------------------
### Get Effective User Email - Apps Script
Source: https://developers.google.com/apps-script/reference/base/session
Logs the email address of the user under whose authority the script is running. This is useful for web apps or installable triggers.
```javascript
// Log the email address of the user under whose authority the script is
// running.
const email = Session.getEffectiveUser().getEmail();
Logger.log(email);
```
--------------------------------
### Create a ChipList with WRAPPED layout
Source: https://developers.google.com/apps-script/reference/card-service/chip-list
Demonstrates how to create a new ChipList and set its layout to WRAPPED, then add a chip to it. This is useful for displaying a list of items that should flow naturally onto new lines.
```javascript
const chip = CardService.newChip();
// Finish building the text chip...
const chipList = CardService.newChipList()
.setLayout(CardService.ChipListLayout.WRAPPED)
.addChip(chip);
```
--------------------------------
### setUpdateType
Source: https://developers.google.com/apps-script/reference/card-service/update-draft-body-action
Sets the `UpdateDraftBodyType` of this update action on the draft body. For example, inserting content at the start, end, or cursor position of the draft body. This method returns the `UpdateDraftBodyAction` object, for chaining.
```APIDOC
## setUpdateType(updateType)
### Description
Sets the `UpdateDraftBodyType` of this update action on the draft body.
### Parameters
#### Path Parameters
- None
#### Query Parameters
- None
#### Request Body
- **updateType** (UpdateDraftBodyType) - Required - The type of update to be performed on an email draft.
### Response
#### Success Response (200)
- **UpdateDraftBodyAction** - This object, for chaining.
### Request Example
```json
{
"updateType": "UpdateDraftBodyType"
}
```
### Response Example
```json
{
"UpdateDraftBodyAction": "object"
}
```
```
--------------------------------
### getStartOffset()
Source: https://developers.google.com/apps-script/reference/document/range-element
Gets the position of the start of a partial range within the range element. For Text elements where isPartial() is true, this returns the index of the first character in the range. Otherwise, it returns -1.
```APIDOC
## getStartOffset()
### Description
Gets the position of the start of a partial range within the range element. If the element is a `Text` element and `isPartial()` returns `true`, the offset is the number of characters before the start of the range (that is, the index of the first character in the range); in any other case, this method returns `-1`.
### Method
`getStartOffset()`
### Return
`Integer` — for `Text` elements, the number of characters before the start of the range; for other elements, `-1`
```
--------------------------------
### getHelpText()
Source: https://developers.google.com/apps-script/reference/forms/list-item
Gets the item's help text.
```APIDOC
## getHelpText()
### Description
Gets the item's help text (sometimes called description text for layout items like `ImageItems`, `PageBreakItems`, and `SectionHeaderItems`).
### Return
`String` - the help text
### Authorization
Scripts that use this method require authorization with one or more of the following scopes:
- `https://www.googleapis.com/auth/forms.currentonly`
- `https://www.googleapis.com/auth/forms`
```
--------------------------------
### BarChartBuilder Example
Source: https://developers.google.com/apps-script/reference/charts/bar-chart-builder
Demonstrates how to create a bar chart using the BarChartBuilder, setting various properties and fetching data from a Google Spreadsheet via a data source URL.
```APIDOC
## BarChartBuilder
Builder for bar charts. For more details, see the Google Charts documentation.
### Example Usage
```javascript
// Get sample data from a spreadsheet.
const dataSourceUrl = 'https://docs.google.com/spreadsheet/tq?range=B1%3AC11' +
'&key=0Aq4s9w_HxMs7dHpfX05JdmVSb1FpT21sbXd4NVE3UEE&gid=0&headers=-1';
const chartBuilder = Charts.newBarChart()
.setTitle('Top Grossing Films in US and Canada')
.setXAxisTitle('USD')
.setYAxisTitle('Film')
.setDimensions(600, 500)
.setLegendPosition(Charts.Position.BOTTOM)
.setDataSourceUrl(dataSourceUrl);
const chart = chartBuilder.build();
```
### Methods
- **build()**: Returns a Chart object representing the built bar chart.
- **reverseCategories()**: Reverses the order of the categories.
- **reverseDirection()**: Reverses the direction of the bar chart (e.g., horizontal to vertical).
- **setBackgroundColor(cssValue)**: Sets the background color of the chart using a CSS color value.
- **setColors(cssValues)**: Sets an array of CSS color values for the chart series.
- **setDataSourceUrl(url)**: Sets the URL of the data source for the chart.
- **setDataTable(tableBuilder)**: Sets the data for the chart using a DataTableBuilder.
- **setDataTable(table)**: Sets the data for the chart using a DataTable.
- **setDataViewDefinition(dataViewDefinition)**: Sets the data view definition for the chart.
- **setDimensions(width, height)**: Sets the width and height of the chart in pixels.
- **setLegendPosition(position)**: Sets the position of the chart legend.
- **setLegendTextStyle(textStyle)**: Sets the text style for the chart legend.
- **setOption(option, value)**: Sets a specific chart option.
- **setRange(start, end)**: Sets the range for the chart axes.
- **setStacked()**: Configures the bar chart to be stacked.
- **setTitle(chartTitle)**: Sets the main title of the chart.
- **setTitleTextStyle(textStyle)**: Sets the text style for the chart title.
- **setXAxisTextStyle(textStyle)**: Sets the text style for the X-axis.
- **setXAxisTitle(title)**: Sets the title for the X-axis.
- **setXAxisTitleTextStyle(textStyle)**: Sets the text style for the X-axis title.
- **setYAxisTextStyle(textStyle)**: Sets the text style for the Y-axis.
- **setYAxisTitle(title)**: Sets the title for the Y-axis.
- **setYAxisTitleTextStyle(textStyle)**: Sets the text style for the Y-axis title.
- **useLogScale()**: Applies a logarithmic scale to the chart axes.
```
--------------------------------
### Checking Element Type
Source: https://developers.google.com/apps-script/reference/document/element-type
This example demonstrates how to get the first child element of a document's body and check its type using `ElementType`. If it's a paragraph, it applies a heading style.
```APIDOC
## Checking Element Type
### Description
This example demonstrates how to get the first child element of a document's body and check its type using `ElementType`. If it's a paragraph, it applies a heading style.
### Method
```javascript
const documentTab = DocumentApp.getActiveDocument().getActiveTab().asDocumentTab();
const firstChild = documentTab.getBody().getChild(0);
if (firstChild.getType() === DocumentApp.ElementType.PARAGRAPH) {
// It's a paragraph, apply a paragraph heading.
firstChild.asParagraph().setHeading(DocumentApp.ParagraphHeading.HEADING1);
}
```
### Parameters
This snippet does not have explicit parameters in the traditional sense, but it utilizes the `DocumentApp` service and its methods.
```
--------------------------------
### Get Calendar Event Title
Source: https://developers.google.com/apps-script/reference/calendar/calendar-event
Retrieves the title of a calendar event. This is useful for identifying events in a calendar. The example shows how to fetch an event within a specific time range and log its title.
```javascript
const calendar = CalendarApp.getCalendarById(
'abc123456@group.calendar.google.com',
);
const event = calendar.getEvents(
new Date('Jan 31, 2023 09:05:00'),
new Date('Jan 31, 2023 09:15:00'),
)[0];
if (event) {
console.log(event.getTitle());
} else {
console.log('No events exist for the specified range');
}
```
--------------------------------
### Get File by ID and Log Name
Source: https://developers.google.com/apps-script/reference/drive/drive-app
Retrieves a file using its ID and logs its name. This example first finds files by name, then uses the ID of the first found file to retrieve it again by ID.
```javascript
// Gets a list of all files in Google Drive with the given name.
// TODO(developer): Replace 'Test' with your file name.
const files = DriveApp.getFilesByName('Test');
if (files.hasNext()) {
// Gets the ID of each file in the list.
const fileId = files.next().getId();
// Gets the file name using its ID and logs it to the console.
console.log(DriveApp.getFileById(fileId).getName());
}
```
--------------------------------
### build()
Source: https://developers.google.com/apps-script/reference/charts/text-style-builder
Builds and returns a text style configuration object that was built using this builder.
```APIDOC
## build()
### Description
Builds and returns a text style configuration object that was built using this builder.
### Return
`TextStyle` — A text style object built using this builder.
### Example
```javascript
// Creates a new text style that uses 26-point blue font.
const textStyleBuilder = Charts.newTextStyle().setColor('#0000FF').setFontSize(26);
const style = textStyleBuilder.build();
```
```
--------------------------------
### Create a Card with Widgets and Actions
Source: https://developers.google.com/apps-script/reference/card-service/card-service
Constructs a detailed card featuring a header with an image, a section with text and an image widget, and a card action to open a link. Demonstrates combining various card components.
```javascript
function createWidgetDemoCard() {
return CardService.newCardBuilder()
.setHeader(
CardService.newCardHeader()
.setTitle('Widget demonstration')
.setSubtitle('Check out these widgets')
.setImageStyle(CardService.ImageStyle.SQUARE)
.setImageUrl('https://www.example.com/images/headerImage.png'),
)
.addSection(
CardService.newCardSection()
.setHeader('Simple widgets') // optional
.addWidget(
CardService.newTextParagraph().setText(
'These widgets are display-only. ' +
'A text paragraph can have multiple lines and ' +
'formatting.',
),
)
.addWidget(
CardService.newImage().setImageUrl(
'https://www.example.com/images/mapsImage.png',
),
),
)
.addCardAction(
CardService.newCardAction().setText('Gmail').setOpenLink(
CardService.newOpenLink().setUrl('https://mail.google.com/mail'),
),
)
.build();
}
```
--------------------------------
### Get Events with Search Options
Source: https://developers.google.com/apps-script/reference/calendar/calendar-app
Fetches events within a time range that also match specific criteria, such as a search term. Filtering by author, search, or status occurs after applying start and max limits.
```javascript
const now = new Date();
const twoHoursFromNow = new Date(now.getTime() + 2 * 60 * 60 * 1000);
const events = CalendarApp.getDefaultCalendar().getEvents(
now,
twoHoursFromNow,
{search: 'meeting'},
);
Logger.log(`Number of events: ${events.length}`);
```
--------------------------------
### Get All Threads for a Gmail Label
Source: https://developers.google.com/apps-script/reference/gmail/gmail-label
Retrieves all threads associated with a given label. Use with caution for labels with a very large number of threads, as it may cause system errors. Consider using `getThreads(start, max)` for large sets.
```javascript
// Log the subject lines of the threads labeled with MyLabel
const label = GmailApp.getUserLabelByName('MyLabel');
const threads = label.getThreads();
for (let i = 0; i < threads.length; i++) {
Logger.log(threads[i].getFirstMessageSubject());
}
```
--------------------------------
### Shortcut Creation Methods
Source: https://developers.google.com/apps-script/reference/drive
Methods for creating shortcuts to Drive items.
```APIDOC
## Shortcut Creation Methods
### Description
Methods to create shortcuts to existing Drive items.
### Methods
- `createShortcut(targetId)`: Creates a shortcut using the target item's ID.
- `createShortcutForTargetIdAndResourceKey(targetId, targetResourceKey)`: Creates a shortcut using the target item's ID and resource key.
```
--------------------------------
### Get Group by Email and Check Membership - Apps Script
Source: https://developers.google.com/apps-script/reference/groups/groups-app
Retrieves a specific group using its email address and checks if the current user is a member. Replace 'example@googlegroups.com' with a valid group email. Requires the `https://www.googleapis.com/auth/groups` scope.
```javascript
const group = GroupsApp.getGroupByEmail('example@googlegroups.com');
const currentUser = Session.getActiveUser();
if (group.hasUser(currentUser)) {
Logger.log('You are a member of this group.');
} else {
Logger.log('You are not a member of this group.');
}
```
--------------------------------
### Create a new Grid
Source: https://developers.google.com/apps-script/reference/card-service/grid
Instantiates a new Grid object, sets its title and number of columns, and adds a grid item. This is a basic example of how to initialize a Grid.
```javascript
const grid = CardService.newGrid().setTitle('My Grid').setNumColumns(2).addItem(
CardService.newGridItem().setTitle('My item'));
```
--------------------------------
### Creating a Hyperlink
Source: https://developers.google.com/apps-script/reference/add-ons-response-service/hyperlink
Example of how to create a new Hyperlink object, set its text, and set its destination URL.
```APIDOC
## Create Hyperlink
### Description
Creates a new Hyperlink object.
### Method
`AddOnsResponseService.newHyperlink()`
### Request Example
```javascript
const hyperLink = AddOnsResponseService.newHyperlink()
.setText("Hyperlink_text")
.setLink("https://www.google.com");
```
```
--------------------------------
### Add a Bookmark to a DocumentTab
Source: https://developers.google.com/apps-script/reference/document/document-tab
Adds a bookmark at a specified position within a document tab. This example demonstrates how to get the tab, append a paragraph, create a position within that paragraph, and then add a bookmark at that position. The bookmark's ID is logged to the console.
```javascript
// Opens the Docs file and retrieves the tab by its IDs. If you created your
// script from within a Google Docs file, you can use
// DocumentApp.getActiveDocument().getActiveTab() instead.
// TODO(developer): Replace the IDs with your own.
const documentTab =
DocumentApp.openById('123abc').getTab('123abc').asDocumentTab();
// Gets the tab body and adds a paragraph.
const paragraph = documentTab.getBody().appendParagraph('My new paragraph.');
// Creates a position at the first character of the paragraph text.
const position = documentTab.newPosition(paragraph.getChild(0), 0);
// Adds a bookmark at the first character of the paragraph text.
const bookmark = documentTab.addBookmark(position);
// Logs the bookmark ID to the console.
console.log(bookmark.getId());
```
--------------------------------
### getHelpText()
Source: https://developers.google.com/apps-script/reference/forms/text-item
Gets the item's help text (sometimes called description text for layout items).
```APIDOC
## getHelpText()
### Description
Gets the item's help text (sometimes called description text for layout items like `ImageItems`, `PageBreakItems`, and `SectionHeaderItems`).
### Return
`String` - The item's help text or description text.
### Authorization
Scripts that use this method require authorization with one or more of the following scopes:
- `https://www.googleapis.com/auth/forms.currentonly`
- `https://www.googleapis.com/auth/forms`
```