### Get Configuration (`config` - Automations) Source: https://airtable.com/developers/scripting/api/input Returns an object containing all input keys mapped to their corresponding values for automations. ```APIDOC ## config (Automations) ### Description Returns an object with all input keys mapped to their corresponding values. ### Method function ### Endpoint Automations only ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript let inputConfig = input.config(); console.log(`The value of myKey is ${inputConfig['myKey']}`); ``` ### Response #### Success Response (200) - `Input Object` - An object where keys are input names and values are the user-provided inputs. #### Response Example ```json { "myKey": "myValue", "anotherKey": 123 } ``` ``` -------------------------------- ### Convert Currencies using External API in Airtable Source: https://airtable.com/developers/scripting/examples/currencyconverter This script fetches currency conversion rates from an external API and updates records in an Airtable base. It requires specifying the table name, the input currency field, and the output currency field. The script handles API fetching and record updates, making it a useful starting point for other API integrations. ```javascript // Change this to the name of a table in your base let table = base.getTable('Invoices'); // Fetch conversion rate from API - you could change this to any API you want let apiResponse = await fetch('https://api.exchangerate.host/latest?base=USD'); let data = await apiResponse.json(); let conversionRate = data.rates.GBP; console.log(`Conversion rate: ${conversionRate}`); // Update all the records let result = await table.selectRecordsAsync({fields: ['Amount (USD)']}); for (let record of result.records) { await table.updateRecordAsync(record, { // Change these names to fields in your base 'Amount (GBP)': record.getCellValue('Amount (USD)') * conversionRate, }); } ``` -------------------------------- ### Create a New Table Asynchronously Source: https://airtable.com/developers/scripting/api/base Provides an example of how to create a new table within an Airtable base using the `createTableAsync` function. It specifies the table name and an initial field, and requires `await` due to its asynchronous nature. ```javascript const tableId = await base.createTableAsync("Tasks", [{name: "Title", type: "singleLineText"}]); ``` -------------------------------- ### Example Usage of input.config.select - JavaScript Source: https://airtable.com/developers/scripting/api/config Demonstrates how to use the `input.config.select` function to configure a 'country' dropdown within an Airtable script. It shows how to define the script's title, description, and the select input item with its options. The selected value is then accessed via the configuration object. ```javascript const config = input.config({ title: 'My cool script', description: 'An awesome script that...', items: [ input.config.select('country', { label: 'Country', description: 'Country in which your business operates', options: [ {label: 'USA', value: 'usa'}, {label: 'UK', value: 'uk'}, {label: 'Australia', value: 'aus'} ] }) ] }); const country = config.country; ``` -------------------------------- ### Configure Script Settings and Read Table Data - JavaScript Source: https://airtable.com/developers/scripting/examples/scriptsettings This JavaScript snippet demonstrates how to configure a script with user-defined settings using `input.config`. It allows users to select a table, a field within that table, and a view in that table. The script then fetches records from the selected view, retrieves the value of the specified field for each record, and prints it to the output. This approach enhances script reusability by allowing non-developers to customize script behavior without modifying the code. ```javascript // Click the "gear" icon in the top right to view settings let config = input.config({ title: 'Your script with settings', description: 'A script that uses settings', items: [ input.config.table('selectedTable', { label: 'Table to use', description: 'Pick any table in this base!', }), input.config.field('selectedField', { label: 'Field inside the above table', parentTable: 'selectedTable', }), input.config.view('selectedView', { label: 'View inside the above table', parentTable: 'selectedTable', }) ] }); // The returned config object will contain the settings selected by the user let selectedField = config.selectedField; let selectedView = config.selectedView; // Get the records (sorted the same as in the view) let query = await selectedView.selectRecordsAsync({ // Only get the field specified by the user fields: [selectedField] }); // Print field from each record for (let record of query.records) { let cellString = record.getCellValueAsString(selectedField) output.text(cellString) } ``` -------------------------------- ### Fetch API: Making a GET request to a JSON API Source: https://airtable.com/developers/scripting/api/fetch Demonstrates how to make a GET request to a JSON API using the fetch API and parse the response as JSON. This function is asynchronous and requires the `await` keyword. ```javascript let response = await fetch('https://api.github.com/orgs/Airtable'); console.log(await response.json()); ``` -------------------------------- ### Create Project and Task Records in Airtable Scripting Source: https://airtable.com/developers/scripting/examples/recordtemplate This script creates a new record in a 'Projects' table and then automatically generates several associated 'Task' records. It prompts the user for a project name and links the tasks back to the newly created project. This functionality is specific to the Airtable Scripting Extension and requires access to the 'Design projects' and 'Tasks' tables. ```javascript // pick tables from your base here let projects = base.getTable('Design projects'); let tasks = base.getTable('Tasks'); // prompt the user to pick a template for our project output.markdown('# New project'); let name = await input.textAsync('Project name'); // create the project - change the field name to one in your base let projectId = await projects.createRecordAsync({ 'Name': name, }); // create the tasks - change the field names to ones from your base. // the [{id: projectId}] links the newly created records back to our project await tasks.createRecordsAsync([ { fields: { 'Name': 'The first task', 'Design project': [{id: projectId}], }, }, { fields: { 'Name': 'Another task', 'Design project': [{id: projectId}], }, }, { fields: { 'Name': 'The final task', 'Design project': [{id: projectId}], }, } ]) output.text('Done!'); ``` -------------------------------- ### Record Picker Script for Airtable Scripting Extension (JavaScript) Source: https://airtable.com/developers/scripting/examples/recordpicker This JavaScript script for the Airtable Scripting Extension prompts the user to select a record from a specified table. If run from a button field, it bypasses the picker and uses the button's record. It includes comments on accessing cell values and handling the selected record, making it a useful starting point for record-based automations. ```javascript // Change this name to use a different table let table = base.getTable("Tasks"); // Prompt the user to pick a record // If this script is run from a button field, this will use the button's record instead. let record = await input.recordAsync('Select a record to use', table); if (record) { // Customize this section to handle the selected record // You can use record.getCellValue("Field name") to access // cell values from the record console.log(`You selected this record: ${record.name}`); } else { console.log('No record was selected'); } ``` -------------------------------- ### Get Text Input via Scripting Extension Source: https://airtable.com/developers/scripting/api/input The textAsync method prompts the user to enter a text string. It is asynchronous and requires an 'await' prefix. This method is specifically for scripting extensions. ```javascript let name = await input.textAsync('What is your name?'); output.text(`Your name is ${name}.`); ``` -------------------------------- ### Generate Airtable Project Reports (JavaScript) Source: https://airtable.com/developers/scripting/examples/customreport This JavaScript script for the Airtable Scripting Extension filters records in a 'Design projects' table and generates a report. It allows users to choose between reports for 'Completed Projects' or 'Incomplete Projects'. The script then summarizes data by category and lists project details, with a total count at the end. It requires access to the 'Design projects' table and its fields: 'Name', 'Category', 'Project lead', 'Client', and 'Complete'. ```javascript let table = base.getTable('Design projects'); let result = await table.selectRecordsAsync({fields: ['Name', 'Category', 'Project lead', 'Client', 'Complete']}); output.markdown('# Project report generator'); let type = await input.buttonsAsync( 'Which report would you like to generate?', [ 'Completed Projects', 'Incomplete Projects', ], ); output.clear(); output.markdown(`# ${type} Report`); let records; if (type === 'Completed Projects') { records = result.records.filter(record => record.getCellValue('Complete')); } else { records = result.records.filter(record => !record.getCellValue('Complete')); } function countByField(records, groupByField) { let counts = {}; for (let record of records) { let key = record.getCellValueAsString(groupByField); if (key in counts) { counts[key] = counts[key] + 1; } else { counts[key] = 1; } } return counts; } output.markdown('## Categories'); let categoryCounts = countByField(records, 'Category'); output.table(categoryCounts); output.markdown('## Projects'); output.table( records.map(record => ({ Name: record.getCellValue('Name'), Category: record.getCellValue('Category'), 'Project lead': record.getCellValue('Project lead'), Client: record.getCellValue('Client'), })), ); output.markdown(`**Total**: ${records.length}`); ``` -------------------------------- ### Summarize Linked Records in Airtable Automation Source: https://airtable.com/developers/scripting/examples/summarizerecords This script retrieves linked records from a specified table, analyzes their status, and generates a summary string. It requires a `recordId` input variable to identify the record containing the links. The output can be used in subsequent automation actions. ```javascript // the table containing record links, and the linked-to table let rootTable = base.getTable("Projects"); let linkedTable = base.getTable("Tasks"); // the record with the links we want to summarize // we need to create a 'recordId' input variable connected to a record trigger let config = input.config(); let recordId = config.recordId; // query the table and find our record according to its id: let rootQuery = await rootTable.selectRecordsAsync({fields: ['Tasks']}); let record = rootQuery.getRecord(recordId); // query for the linked records: let linkedQuery = await linkedTable.selectRecordsAsync({fields: ['Status']}); let linkedRecords = (record.getCellValue("Tasks") || []).map((link) => linkedQuery.getRecord(link.id) ); // analyze linked records to produce summary: let incompleteRecords = linkedRecords.filter( (linkedRecord) => linkedRecord.getCellValueAsString("Status") !== "Done" ); let completedCount = linkedRecords.length - incompleteRecords.length; let summary = ` ${completedCount}/${linkedRecords.length} tasks completed! Remaining tasks: `; for (let incomplete of incompleteRecords) { summary += `- ${incomplete.name} (${incomplete.getCellValueAsString( "Status" )}) `; } console.log(summary); // output the summary so it can be used in subsequent automation actions: output.set("Summary", summary); ``` -------------------------------- ### Define Table Setting with input.config.table Source: https://airtable.com/developers/scripting/api/config This JavaScript code shows how to specifically define a table setting within `input.config`. The `input.config.table` function creates a UI element for users to select a table, with optional labels and descriptions to guide them. The selected table is then accessible via the returned configuration object. ```javascript function ( key: string, options?: { label?: string, description?: string } ) => void; const config = input.config({ title: 'My cool script', description: 'An awesome script that...', items: [ input.config.table('ordersTable', { label: 'Orders table', description: 'Table in which you track orders', }) ] }); const ordersTable = config.ordersTable; ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/table/view Covers how to configure script settings, including 'Config', 'Table', 'Field', 'Text', 'Number', and 'Select' settings. ```APIDOC ## Script Settings This section describes how to configure settings for your scripts. ### Setting Types - **Config** - For general configuration. - **Table** - To specify a table setting. - **Field** - To specify a field setting. - **Text** - For text input settings. - **Number** - For numeric input settings. - **Select** - For selection-based settings. ``` -------------------------------- ### Getting Collaborator ID in Airtable Scripting Source: https://airtable.com/developers/scripting/api/collaborator This example shows how to retrieve the unique ID of a collaborator using their email address. The `base.getCollaborator()` method is used, and the `.id` property accesses the collaborator's ID. ```javascript // Get the id of a collaborator: let collaborator = base.getCollaborator("logan.grandmont@airtable.com"); console.log(`Collaborator ID: ${collaborator.id}`); ``` -------------------------------- ### Getting Collaborator Email in Airtable Scripting Source: https://airtable.com/developers/scripting/api/collaborator This example demonstrates retrieving the email address of a collaborator. It uses `base.getCollaborator()` with a collaborator ID and accesses the `.email` property. For user group collaborators, this returns an RFC 2822 compliant list of emails. ```javascript // Get the email of a collaborator: let collaborator = base.getCollaborator("usrfnewKli7n9H8np"); console.log(`Collaborator email: ${collaborator.email}`); ``` -------------------------------- ### Scripting API - User Input Source: https://airtable.com/developers/scripting/api/table/record Documentation for handling user input via configuration, text, buttons, and selections of tables, views, fields, or records. ```APIDOC ## Scripting API - User Input ### Description This section details the methods and objects for gathering input from the user through various interactive elements. ### Input Types - **Config**: For general configuration input. - **Text**: To receive text input from the user. - **Buttons**: To present and handle button interactions. - **Table**: To allow users to select a table. - **View**: To allow users to select a view. - **Field**: To allow users to select a field. - **Record**: To allow users to select one or more records. - **File**: For handling file uploads. ``` -------------------------------- ### Inspect Active Table Object using Airtable Cursor Source: https://airtable.com/developers/scripting/api/cursor This example shows how to get the active table ID from the cursor and then retrieve the entire table object. This allows for further inspection of the table's properties and methods within the Airtable Scripting environment. ```javascript // inspect the active table: let tableId = cursor.activeTableId; let table = base.getTable(tableId); console.log(table); ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/table/view Details the various ways scripts can receive user input, including 'Config', 'Text', 'Buttons', 'Table', 'View', 'Field', 'Record', and 'File' inputs. ```APIDOC ## User Input This section describes how to capture user input within your scripts. ### Input Types - **Config** - For configuration settings. - **Text** - For text-based input. - **Buttons** - For interactive button inputs. - **Table** - For selecting a table. - **View** - For selecting a view. - **Field** - For selecting a field. - **Record** - For selecting one or more records. - **File** - For file uploads. ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/recordqueryresult/table Handle user input and configurations for scripts. ```APIDOC ## User Input This section describes how to handle and configure user inputs for scripts. ### Input Types: - **Config**: General script configuration settings. - **Text**: Text-based user input. - **Buttons**: Interactive buttons for user actions. - **Table**: User selection of a table. - **View**: User selection of a view. - **Field**: User selection of a field. - **Record**: User selection of one or more records. - **File**: User uploading a file. ``` -------------------------------- ### Scripting API - Script Settings Source: https://airtable.com/developers/scripting/api/table/record Documentation for configuring script settings such as tables, fields, text, and number inputs. ```APIDOC ## Scripting API - Script Settings ### Description This section covers how to configure various settings for your script, including user interface elements and data source selections. ### Setting Types - **Config**: For general script configuration. - **Table**: To configure table selections for the script. - **Field**: To configure field selections. - **Text**: To configure text input fields. - **Number**: To configure numeric input fields. - **Select**: To configure select (dropdown) input fields. ``` -------------------------------- ### Script Output Source: https://airtable.com/developers/scripting/api/record/view Details on how to present script output to the user, including setting text, tables, inspecting values, and clearing output. ```APIDOC ## Script Output This section covers methods for displaying output from scripts. ### Output Methods - **Set** - Sets the output content. - **Text** - Displays text output. - **Table** - Displays tabular data. - **Inspect** - Inspects variable values. - **Clear** - Clears the output area. ``` -------------------------------- ### Script Settings Objects Source: https://airtable.com/developers/scripting/api/view/field Objects for configuring script settings and parameters. ```APIDOC ## Script Settings Objects ### Description These objects allow you to configure various settings for your script, such as tables, fields, and text inputs. ### Method N/A (Script Settings Objects) ### Endpoint N/A (Script Settings Objects) ### Parameters N/A (Script Settings Objects) ### Request Example N/A (Script Settings Objects) ### Response #### Success Response (N/A) - **Config** (object) - For general configuration settings. - **Table** (object) - For table settings. - **Field** (object) - For field settings. - **Text** (object) - For text input settings. - **Number** (object) - For number input settings. - **Select** (object) - For select input settings. ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/record/table Information on configuring script-specific settings. ```APIDOC ## Script Settings ### Description Objects for configuring various settings related to the script's behavior and appearance. ### Settings Objects - **Config**: For general configuration settings. - **Table**: To associate the script with a specific table. - **Field**: To associate the script with a specific field. - **Text**: For text-based settings. - **Number**: For numerical settings. - **Select**: For dropdown or selection-based settings. ``` -------------------------------- ### Clear Output in Scripting Extension Source: https://airtable.com/developers/scripting/api/output The `output.clear` function removes all previously displayed output. This is useful for resetting the output area, for example, before displaying new results. ```javascript async function () => Promise; output.clear(); ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/cell_values/cell_values Define and handle user input for configurable script parameters. ```APIDOC ## User Input Configure and manage user inputs for your scripts. ### Input Types * **Config**: General configuration settings. * **Text**: Text input field. * **Buttons**: Button input for triggering actions. * **Table**: Selection of a table. * **View**: Selection of a view. * **Field**: Selection of a field. * **Record**: Selection of one or more records. * **File**: File upload input. ``` -------------------------------- ### Get Table ID - JavaScript Source: https://airtable.com/developers/scripting/api/table Retrieves and logs the unique identifier for a specified table within an Airtable base. This is useful for referencing tables programmatically. ```javascript let table = base.getTable("Tasks"); console.log(`Table id: ${table.id}`); ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/cell_values/collaborator APIs for configuring script settings. ```APIDOC ## Script Settings ### Description APIs for configuring various settings for the script. ### Settings Configuration - **Config** - General configuration settings. - **Table** - Settings related to table selection. - **Field** - Settings related to field selection. - **Text** - Settings for text inputs. - **Number** - Settings for number inputs. - **Select** - Settings for select inputs. ``` -------------------------------- ### Get Record ID in JavaScript Source: https://airtable.com/developers/scripting/api/record Retrieves the unique identifier for a given Airtable record. This requires selecting records from a table or view first. The ID is a string. ```javascript let table = base.getTable("Tasks"); let queryResult = await table.selectRecordsAsync({fields: []}); let record = queryResult.records[0]; console.log(record.id); ``` -------------------------------- ### Get Airtable View Name Source: https://airtable.com/developers/scripting/api/view Retrieves the name of an Airtable view. The name is a user-defined string that identifies the view in the Airtable UI. This is useful for displaying or logging view information. ```javascript let table = base.getTable("People"); let view = table.getView("Grid View"); console.log(`View name: ${view.name}`); ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/config/field Handle user input and configuration through various UI elements like text fields, buttons, and selection controls. ```APIDOC ## User Input ### Description Defines methods and objects for gathering input from the user through the scripting interface. ### Input Types - **Config** (object) - For configuring script settings. - **Text** (object) - For text-based input. - **Buttons** (object) - For creating interactive buttons. - **Table** (object) - For selecting tables. - **View** (object) - For selecting views. - **Field** (object) - For selecting fields. - **Record** (object) - For selecting records. - **File** (object) - For file uploads. ``` -------------------------------- ### Get Airtable View ID Source: https://airtable.com/developers/scripting/api/view Retrieves the unique identifier (ID) of an Airtable view. The ID is a string that uniquely identifies the view within the base. This is useful for referencing the view programmatically. ```javascript let table = base.getTable("Projects"); let view = table.getView("By Launch Date"); console.log(`View id: ${view.id}`); ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/config/view APIs for configuring and managing script settings. ```APIDOC ## Script Settings This section describes how to configure and manage settings for your script. ### Settings Components - **Config** (object) - For general script configuration. - **Table** (object) - For configuring table-related settings. - **Field** (object) - For configuring field-related settings. - **Text** (object) - For text-based settings. - **Number** (object) - For numerical settings. - **Select** (object) - For selection-based settings. ``` -------------------------------- ### Get input configuration (Automations) Source: https://airtable.com/developers/scripting/api/input Returns an object containing all input keys mapped to their corresponding values for use in Airtable Automations. This function is used to retrieve values configured by the user for an automation. ```javascript function () => Input Object; ``` ```javascript let inputConfig = input.config(); console.log(`The value of myKey is ${inputConfig['myKey']}.`); ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/base/record Provides access to objects for configuring script settings, allowing users to define parameters like tables, fields, and text inputs. ```APIDOC ## Script Settings This section describes objects used for configuring script settings. ### Settings Objects - **Config**: For general configuration settings. - **Table**: To select a table for settings. - **Field**: To select a field for settings. - **Text**: For text-based settings. - **Number**: For numerical settings. - **Select**: For selection-based settings. ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/view/base APIs for configuring script settings, including tables, fields, text, and numbers. ```APIDOC ## Script Settings ### Description APIs for configuring script settings and parameters. ### Setting Types - **Config**: General script configuration. - **Table**: Settings related to table selection. - **Field**: Settings related to field selection. - **Text**: Settings for text input fields. - **Number**: Settings for numerical input fields. - **Select**: Settings for select input fields. ``` -------------------------------- ### Get Airtable View Type Source: https://airtable.com/developers/scripting/api/view Determines the type of an Airtable view. View types include 'grid', 'form', 'calendar', 'gallery', and 'kanban'. This helps in understanding how the view is presented in the UI and how to interact with it. ```javascript for (let view of base.getTable("Tasks").views) { console.log(`View "${view.name}" has type "${view.type}".`); } ``` -------------------------------- ### Get Airtable View Object Source: https://airtable.com/developers/scripting/api/view Retrieves a View object from a specified table. This is the initial step to access view properties or perform operations on the view. It requires the table name and the view name. ```javascript let table = base.getTable("Tasks"); let view = table.getView("Todo"); console.log(view); ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/config/field Configure various settings for your script, including tables, fields, and text inputs. ```APIDOC ## Script Settings ### Description Allows you to define and manage configuration settings for your script, such as target tables, fields, and input prompts. ### Setting Types - **Config** (object) - General configuration settings. - **Table** (object) - For specifying target tables. - **Field** (object) - For specifying target fields. - **Text** (object) - For text-based configuration inputs. - **Number** (object) - For numerical configuration inputs. - **Select** (object) - For dropdown selection configuration inputs. ``` -------------------------------- ### Get Field Type in Airtable Source: https://airtable.com/developers/scripting/api/field Explains how to determine the data type of a field in Airtable. This is crucial for understanding what kind of data a field holds and how to process it. It iterates through all fields in a table and logs their names and types. ```javascript // show the type of every field in "Tasks" for (let field of base.getTable("Tasks").fields) { console.log(`Field "${field.name}" has type "${field.type}".`); } ``` -------------------------------- ### Get Field by ID or Name - JavaScript Source: https://airtable.com/developers/scripting/api/table Demonstrates how to retrieve a specific field from a table using either its unique ID or its human-readable name. This method is crucial for accessing and manipulating individual field data. ```javascript // Get a field by id: let field1 = base.getTable("Projects").getField("fldZadh0dq9P2Xqry"); console.log(field1); // Get a field by name: let field2 = base.getTable("People").getField("Role"); console.log(field2); ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/view/base Defines the various ways users can provide input to scripts, including configuration, text, buttons, and selections. ```APIDOC ## User Input ### Description Mechanisms for scripts to receive input from users. ### Input Types - **Config**: Script configuration inputs. - **Text**: Simple text input from the user. - **Buttons**: Interactive buttons for user actions. - **Table**: User selection of a table. - **View**: User selection of a view. - **Field**: User selection of a field. - **Record**: User selection of records. - **File**: User upload of files. ``` -------------------------------- ### Get Airtable View URL Source: https://airtable.com/developers/scripting/api/view Retrieves the URL for an Airtable view. This URL can be used to directly access the view in the Airtable UI via a web browser. It's helpful for creating links to specific views. ```javascript for (let view of base.getTable("Projects").views) { console.log(`[Click to open ${view.name}](${view.url})`); } ``` -------------------------------- ### Access Field Name in Airtable Source: https://airtable.com/developers/scripting/api/field Illustrates how to get the name of a field in Airtable. Field names are human-readable identifiers and are commonly used for display purposes or for user-facing logic. It accesses the `name` property of a field object. ```javascript // Show a field name let table = base.getTable("People"); let field = table.getField("Role"); console.log(`Field name: ${field.name}`); ``` -------------------------------- ### Scripting API Reference Source: https://airtable.com/developers/scripting/api/recordqueryresult/record This section details the global variables and core data structures available within the Airtable scripting environment. ```APIDOC ## Scripting API Reference This is the API reference for scripting. Use the sidebar on the left to explore the most important concepts, or use the search bar at the top of this panel to find a specific class or method. ### Global Variables - **base**: Represents the current Airtable base. - **cursor**: Provides access to the current cursor position within a table or view. - **session**: Information about the current scripting session. - **input**: Object for handling user input within the script. - **output**: Object for managing script output. - **fetch**: Function for making HTTP requests. - **secrets**: Access to secret variables configured for the script. ### Base Data Structures - **Base**: Represents an Airtable base. - **Table**: Represents a table within a base. - **View**: Represents a view within a table. - **Field**: Represents a field within a table. - **RecordQueryResult**: Represents the result of a query for records. - **Record**: Represents a single record in a table. - **Cell values & field options**: Access to cell data and field configurations. ### Other Metadata - **Session**: Details about the current session. - **Collaborator**: Information about collaborators on the base. ### User Input Components - **Config**: For script configuration input. - **Text**: For text-based user input. - **Buttons**: For creating interactive buttons. - **Table**: For selecting tables. - **View**: For selecting views. - **Field**: For selecting fields. - **Record**: For selecting records. - **File**: For file input. ### Script Output Components - **Set**: For setting output values. - **Text**: For displaying text output. - **Table**: For displaying tabular output. - **Inspect**: For inspecting data structures. - **Clear**: To clear the script output. ### Script Settings Components - **Config**: For script configuration settings. - **Table**: For setting default tables. - **Field**: For setting default fields. - **Text**: For text input settings. - **Number**: For number input settings. - **Select**: For select input settings. ### Notes This website uses cookies and other tracking technologies. By continuing to use this site, you agree to our use of these tracking technologies in accordance with our Privacy Policy and Cookie Policy, and accept our Terms of Service. Cookie Preferences ``` -------------------------------- ### Get Record Primary Cell Value as String in JavaScript Source: https://airtable.com/developers/scripting/api/record Retrieves the primary cell value of an Airtable record as a string. If the primary cell is empty, it returns 'Unnamed record'. This provides a human-readable name for the record. ```javascript let table = base.getTable("Tasks"); let queryResult = await table.selectRecordsAsync({fields: []}); let record = queryResult.records[0]; console.log(record.name); ``` -------------------------------- ### Scripting API Reference Source: https://airtable.com/developers/scripting/api Documentation for the Airtable scripting API, including global variables and different categories of functionalities. ```APIDOC ## Scripting API Reference This is the API reference for scripting. Use the sidebar on the left to explore the most important concepts, or use the search bar at the top of this panel to find a specific class or method. ### Global Variables - **base** - **cursor** - **session** - **input** - **output** - **fetch** - **secrets** ### Base Data - **Base** - **Table** - **View** - **Field** - **RecordQueryResult** - **Record** - **Cell values & field options** ### Other Metadata - **Session** - **Collaborator** ### User Input - **Config** - **Text** - **Buttons** - **Table** - **View** - **Field** - **Record** - **File** ### Script Output - **Set** - **Text** - **Table** - **Inspect** - **Clear** ### Script Settings - **Config** - **Table** - **Field** - **Text** - **Number** - **Select** ``` -------------------------------- ### Getting Collaborator Name in Airtable Scripting Source: https://airtable.com/developers/scripting/api/collaborator This snippet illustrates how to fetch the name of a collaborator by their email. It employs `base.getCollaborator()` and then accesses the `.name` property. Note that the name can be null if the user's account lacks a name. ```javascript // Get the name of a collaborator: let collaborator = base.getCollaborator("jess.patel@airtable.com"); console.log(`Collaborator name: ${collaborator.name}`); ``` -------------------------------- ### Script Output Source: https://airtable.com/developers/scripting/api/record/table Details the objects and methods for controlling what the script displays or outputs. ```APIDOC ## Script Output ### Description Methods and objects for controlling the output and display of information from your script. ### Output Objects - **Set**: To set output values. - **Text**: To display text output. - **Table**: To display data in a table format. - **Inspect**: To inspect complex data structures. - **Clear**: To clear the script output. ``` -------------------------------- ### Script Settings Source: https://airtable.com/developers/scripting/api/cell_values/cell_values Configure settings for your Airtable script. ```APIDOC ## Script Settings Configure various settings for your script. ### Setting Types * **Config**: General configuration settings. * **Table**: Select a table for settings. * **Field**: Select a field for settings. * **Text**: Text input for settings. * **Number**: Number input for settings. * **Select**: Select from a list of options for settings. ``` -------------------------------- ### Get View by ID or Name - JavaScript Source: https://airtable.com/developers/scripting/api/table Shows how to retrieve a specific view from a table using either its unique ID or its name. This function is essential for working with different data subsets or presentations within a table. ```javascript // Get a view by id: let view1 = base.getTable("Tasks").getView("viwdEK4BDWcrW3unJ"); console.log(view1); // Get a view by name: let view2 = base.getTable("Projects").getView("By Category"); console.log(view2); ``` -------------------------------- ### Get Field Object in Airtable Source: https://airtable.com/developers/scripting/api/field Demonstrates how to retrieve a specific field object from a table within an Airtable base. It uses the `getTable` and `getField` methods to access the desired field. This is a foundational step for interacting with field data. ```javascript let table = base.getTable("Tasks"); let field = table.getField("Description"); console.log(field); ``` -------------------------------- ### File Upload and Parsing (`fileAsync`) Source: https://airtable.com/developers/scripting/api/input Prompts the user to import a file and returns the file object. If the file is a text-based format (txt, xls, xlsx, csv, json, xml), it will also attempt to parse the file content. ```APIDOC ## fileAsync ### Description Prompts the user to import a file. Returns the imported File object. If the imported file is a .txt, .xls, .xlsx, .csv, .json, or .xml file, it will also attempt to parse the file and return the parsed contents. ### Method async function ### Endpoint Scripting Extension only ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None **Parameters:** - `label` (string) - Required - A label explaining what file being requested. - `options` (object) - Optional - Options for the file input. - `options.allowedFileTypes` (Array) - Optional - Which file types can be imported. Like input#accept, these can be a mix of mime types and extension names, e.g. '.xlsx', 'application/json', 'image/*'. If omitted, all file types are allowed. - `options.hasHeaderRow` (boolean) - Optional - Only affects '.xls', '.xlsx', and '.csv' files. If set to true, each parsed row will be an object with keys determined from the header row. If false, each row will be arrays of strings. Defaults to false. - `options.useRawValues` (boolean) - Optional - Only affects '.xls', '.xlsx', and '.csv' files. If set to true, the raw cell and header values will be returned as strings. If false, cell and header values will be automatically parsed (e.g. numbers will be converted from string to number type, dates will be converted to Date objects). Defaults to false. ### Request Example ```javascript let fileResult = await input.fileAsync( 'Import a CSV file with header row', { allowedFileTypes: ['.csv'], hasHeaderRow: true } ); output.text(`You uploaded the '${fileResult.file.name}' file.`); output.table(fileResult.parsedContents); ``` ### Response #### Success Response (200) - `file` (File) - The imported File object. - `parsedContents` (any) - The parsed content of the file if it's a supported text-based format, otherwise undefined. #### Response Example ```json { "file": {"name": "example.csv", "size": 1234, "type": "text/csv"}, "parsedContents": [ {"column1": "value1", "column2": "value2"} ] } ``` ``` -------------------------------- ### Script Output Objects Source: https://airtable.com/developers/scripting/api/view/field Objects for controlling and formatting the output of your scripts. ```APIDOC ## Script Output Objects ### Description These objects provide methods to control how your script's output is presented to the user. ### Method N/A (Script Output Objects) ### Endpoint N/A (Script Output Objects) ### Parameters N/A (Script Output Objects) ### Request Example N/A (Script Output Objects) ### Response #### Success Response (N/A) - **Set** (method) - Sets the script output. - **Text** (method) - Outputs text. - **Table** (method) - Outputs a table. - **Inspect** (method) - Inspects script output. - **Clear** (method) - Clears the script output. ``` -------------------------------- ### Get Record Cell Value in JavaScript Source: https://airtable.com/developers/scripting/api/record Retrieves the value of a specific cell within an Airtable record. You can specify the field by its Field object, ID, or name. The returned value's format depends on the field type. ```javascript let table = base.getTable("Tasks"); let queryResult = await table.selectRecordsAsync({fields: ["Description"]}); let record = queryResult.records[0]; console.log(record.getCellValue("Description")); ``` -------------------------------- ### Get Record Cell Value as String in JavaScript Source: https://airtable.com/developers/scripting/api/record Retrieves the value of a specific cell within an Airtable record, always formatted as a string. This is useful for consistent display or logging. Requires specifying the field by its Field object, ID, or name. ```javascript let table = base.getTable("Tasks"); let queryResult = await table.selectRecordsAsync({fields: ["Priority"]}); let record = queryResult.records[0]; console.log(record.getCellValueAsString("Priority")); ``` -------------------------------- ### Script Output Source: https://airtable.com/developers/scripting/api/recordqueryresult/table Format and display script output to the user. ```APIDOC ## Script Output Control how your script's results are presented to the user. ### Output Methods: - **Set**: Set script output values. - **Text**: Display text-based output. - **Table**: Display results in a tabular format. - **Inspect**: Inspect script variables and data structures. - **Clear**: Clear the script output area. ``` -------------------------------- ### Getting Collaborator Profile Picture URL in Airtable Scripting Source: https://airtable.com/developers/scripting/api/collaborator This snippet shows how to obtain the URL for a collaborator's profile picture. It uses `base.getCollaborator()` and accesses the `.profilePicUrl` property. This URL can be null for users without a picture or for user groups. ```javascript // Show the profile picture of a collaborator: let collaborator = base.getCollaborator("sandy.hagen@airtable.com"); console.log(`Collaborator picture: ![profile picture](${collaborator.profilePicUrl})`); ``` -------------------------------- ### Airtable Scripting API - Script Settings Source: https://airtable.com/developers/scripting/api/view/record Details on configuring script settings, including tables, fields, and text inputs. ```APIDOC ## Script Settings ### Description Allows configuration of various script settings and parameters. ### Setting Types - **Config** (object) - For general script configurations. - **Table** (object) - For setting default or selected tables. - **Field** (object) - For setting default or selected fields. - **Text** (object) - For setting text-based configuration values. - **Number** (object) - For setting numerical configuration values. - **Select** (object) - For creating dropdown selections for configuration. ``` -------------------------------- ### Update Multiple Select Field Options Source: https://airtable.com/developers/scripting/api/cell_values This example demonstrates how to update options for a 'multipleSelects' field in Airtable. It shows how to add a new choice while preserving existing ones. To enable deletion of choices, an additional option can be passed. ```javascript const multipleSelectField = table.getField('My multiple select field'); await multipleSelectField.updateOptionsAsync({ choices: [ ...multipleSelectField.options.choices, {name: 'My new choice'}, ], }); ``` ```javascript const multipleSelectField = table.getField('My multiple select field'); await multipleSelectField.updateOptionsAsync( { choices: multipleSelectField.options.choices.filter((choice) => choice.name !== 'Choice to delete'), }, {enableSelectFieldChoiceDeletion: true}, ); ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/config/view APIs for handling user input and configuration within Airtable scripts. ```APIDOC ## User Input This section describes the components used for gathering input from the user. ### Input Components - **Config** (object) - For general configuration input. - **Text** (object) - For text-based input. - **Buttons** (object) - For creating interactive buttons. - **Table** (object) - For selecting or inputting table data. - **View** (object) - For selecting or inputting view data. - **Field** (object) - For selecting or inputting field data. - **Record** (object) - For selecting or inputting records. - **File** (object) - For handling file uploads or selections. ``` -------------------------------- ### Airtable Scripting API - Script Output Source: https://airtable.com/developers/scripting/api/view/record Documentation for managing and displaying script output to the user. ```APIDOC ## Script Output ### Description Manages and presents the output generated by the script. ### Output Methods - **Set** (method) - Sets the output content. - **Text** (method) - Displays text output. - **Table** (method) - Displays tabular output. - **Inspect** (method) - Provides detailed inspection of data. - **Clear** (method) - Clears the script output area. ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/cell_values/collaborator APIs for handling user input within scripts. ```APIDOC ## User Input ### Description APIs for gathering various types of input from the user running the script. ### Input Types - **Config** - For configuring script settings. - **Text** - For text-based input. - **Buttons** - For presenting buttons to the user. - **Table** - For selecting tables. - **View** - For selecting views. - **Field** - For selecting fields. - **Record** - For selecting records. - **File** - For file uploads. ``` -------------------------------- ### Get Button Choice via Scripting Extension Source: https://airtable.com/developers/scripting/api/input The buttonsAsync method prompts the user to select one option from a list of choices presented as buttons. Options can be simple strings or objects with labels and optional values or variants. It returns the selected label or value and is asynchronous. ```javascript let catOrDog = await input.buttonsAsync('Cats or dogs?', ['Cats!', 'Dogs!']); if (catOrDog === 'Cats!') { output.text('Meow'); } else { output.text('Woof'); } ``` ```javascript let shouldContinue = await input.buttonsAsync( 'Should we delete all the records in your base?', [ {label: 'Cancel', value: 'cancel'}, {label: 'Go for it', value: 'yes', variant: 'danger'}, ], ); if (shouldContinue === 'yes') { output.text('I refuse!'); } ``` ```javascript let today = new Date(); let tomorrow = new Date(); tomorrow.setDate(today.getDate() + 1); let date = await input.buttonsAsync( 'When should this event start?', [ {label: 'Today', value: today}, {label: 'Tomorrow', value: tomorrow}, ], ); output.text(date.toDateString()); ``` -------------------------------- ### User Input Source: https://airtable.com/developers/scripting/api/base/record Defines the objects and methods for handling user input within the scripting interface, allowing scripts to prompt users for configuration or data. ```APIDOC ## User Input This section details the objects available for gathering input from the user. ### Input Objects - **Config**: For general configuration input. - **Text**: To get text input from the user. - **Buttons**: To present buttons for user interaction. - **Table**: To select a table. - **View**: To select a view. - **Field**: To select a field. - **Record**: To select records. - **File**: To allow file uploads. ``` -------------------------------- ### Update Field Description Asynchronously in Airtable Source: https://airtable.com/developers/scripting/api/field Provides an example of how to asynchronously update the description of a field in Airtable using the `updateDescriptionAsync` method. This function takes the new description as a string or null and returns a Promise. It's important to use `await` to ensure the update completes. ```javascript let table = base.getTable("Projects"); let field = table.getField("Category"); await field.updateDescriptionAsync('New description'); ```