Script Context
Every script action receives a single context parameter — a ScriptContext instance that provides access to the connection, table, records, and other variables relevant to the action being executed.
Always Available
These properties are available in every script action:
| Property | Type | Description |
|---|---|---|
context.connection |
APIConnection | The active API connection with authentication and session. Use context.connection.request() for HTTP requests. |
context.table |
APITable | The table being operated on. Has fields (dict of Field objects), name, primary_key_field, etc. |
context.table_name |
str | The name of the table (convenience shorthand for context.table.name). |
context.logger |
Logger | Structured logger. Use context.logger.info(), .warning(), .error(). |
context.stop_check |
Callable | None | Cancellation check. Call context.stop_check() in long loops to raise if execution has been cancelled. May be None for actions invoked outside an execution context (e.g. ad-hoc connection tests); guard with if context.stop_check: context.stop_check(). |
context.username |
str | The username from the connection's credentials. |
context.adaptor_directory |
str | Absolute path to the adaptor's directory on disk. |
Action-Specific Properties
These properties are only populated for certain action types:
| Property | Type | Available In | Description |
|---|---|---|---|
context.record |
Record | insert, update, extract_attachment_metadata, extract_attachment, insert_attachment | The single record being processed. |
context.records |
list[Record] | insert_multiple, update_multiple | The batch of records being processed. |
context.existing_records |
list[Record] | update_multiple | The existing records before update (useful for computing deltas). |
context.record_id |
str | extract_single, update, extract_attachment_metadata, extract_attachment, insert_attachment | The target record's primary key value. |
context.query |
Query | None | extract, source_count | A filter query, if provided by the caller. |
context.fields |
list[str] | None | extract | Requested field names, or None for all fields. |
context.limit |
int | None | extract | Maximum number of records to return. |
context.offset |
int | None | extract | Number of records to skip (for pagination). |
context.attachment_metadata |
AttachmentMetadata | extract_attachment | Metadata for the specific attachment to download. |
context.attachment |
Attachment | insert_attachment | The attachment to upload. |
Available Global Classes
These classes are available in the script's global scope without any import:
| Class | Description |
|---|---|
Record |
Data record. See Record reference. |
Field |
Field definition. See Field reference. |
Attachment |
File data with base64 content. See Attachment reference. |
AttachmentMetadata |
Lightweight file metadata. See Attachment reference. |
Variable |
Connection variable. |
DataTypes |
Data-type enum. |
ScriptContext |
The context class itself (for type hints). |
Standard Python builtins (print, len, range, dict, list, int, str, float, bool, enumerate, zip, sorted, min, max, sum, any, all, isinstance, type, round, abs, open, etc.) are also available.
APITable Properties
The context.table object provides useful metadata about the table:
| Property | Type | Description |
|---|---|---|
context.table.name |
str | The table name. |
context.table.fields |
dict[str, Field] | Dictionary of field definitions keyed by field name. |
context.table.primary_key_field |
Field | None | The primary key Field object, if defined. |
context.table.primary_key_field_name |
str | None | The name of the primary key field. |
context.table.label |
str | None | Display label for the table. |
context.table.description |
str | None | Table description. |
Allowed Imports
Scripts can import from a restricted set of packages. Common useful imports include:
-
json— JSON parsing and serialisation -
base64— Base64 encoding/decoding (for attachments) -
re— Regular expressions -
math— Mathematical functions -
datetime— Date and time handling -
hashlib— Hashing -
urllib— URL parsing -
xml— XML parsing
Comments
0 comments
Please sign in to leave a comment.