ctx.collection
The Collection instance associated with the current RunJS execution context, used to access collection metadata, field definitions, primary keys, and other configurations. It usually originates from ctx.blockModel.collection or ctx.collectionField?.collection.
Use Cases
Note:
ctx.collectionis available in scenarios where a data block, form block, or table block is bound to a collection. In an independent JSBlock that is not bound to a collection, it may benull. It is recommended to perform a null check before use.
Type Definition
Common Properties
Common Methods
Relationship with ctx.collectionField and ctx.blockModel
In scenarios like sub-tables, ctx.collection might be the association target collection; in standard forms/tables, it is usually the collection bound to the block.
Examples
Get Primary Key and Open Popup
Iterate Through Fields for Validation or Linkage
Get Association Fields
Notes
filterTargetKeyis the primary key field name of the collection. Some collections may use astring[]for composite primary keys. If not configured,'id'is commonly used as a fallback.- In scenarios like sub-tables or association fields,
ctx.collectionmay point to the association target collection, which differs fromctx.blockModel.collection. getFields()merges fields from inherited collections; local fields override inherited fields with the same name.
Related
- ctx.collectionField: The collection field definition of the current field
- ctx.blockModel: The parent block hosting the current JS, containing
collection - ctx.model: The current model, which may contain
collection

