ctx.dataSource
The DataSource instance bound to the current RunJS execution context, used to access collections, field metadata, and manage collection configurations within the current data source. It usually corresponds to the data source selected for the current page or block (e.g., the main database main).
Use Cases
Note:
ctx.dataSourcerepresents a single data source for the current context. To enumerate or access other data sources, please use ctx.dataSourceManager.
Type Definition
Common Properties
Common Methods
Relationship with ctx.dataSourceManager
Example
Get Collections and Fields
Get Association Fields
Iterate Through Collections for Dynamic Processing
Perform Validation or Dynamic UI Based on Field Metadata
Notes
- The path format for
getCollectionField(fieldPath)iscollectionName.fieldPath, where the first segment is the collection name and the subsequent segments are the field path (supports associations, e.g.,user.name). getCollection(name)supports thecollectionName.fieldNameformat, returning the target collection of the association field.- In the RunJS context,
ctx.dataSourceis usually determined by the data source of the current block or page. If no data source is bound to the context, it may beundefined; it is recommended to perform a null check before use.
Related
- ctx.dataSourceManager: Data source manager, manages all data sources.
- ctx.collection: The collection associated with the current context.
- ctx.collectionField: The collection field definition for the current field.

