The FlowResource instance in the current context, used to access and operate on data. In most blocks (Forms, Tables, Details, etc.) and pop-up scenarios, the runtime environment pre-binds ctx.resource. In scenarios like JSBlock where there is no resource by default, you must first call ctx.initResource() to initialize it before using it via ctx.resource.
ctx.resource can be used in any RunJS scenario that requires access to structured data (lists, single records, custom APIs, SQL). Forms, Tables, Detail blocks, and pop-ups are typically pre-bound. For JSBlock, JSField, JSItem, JSColumn, etc., if data loading is required, you can call ctx.initResource(type) first and then access ctx.resource.
ctx.resource is the corresponding resource instance.undefined until ctx.initResource(type) is called.Methods exposed by different resource types (MultiRecordResource, SingleRecordResource, APIResource, SQLResource) vary slightly. Below are the universal or commonly used methods:
| Method | Description |
|---|---|
getData() | Get current data (list or single record) |
setData(value) | Set local data |
refresh() | Initiate a request with current parameters to refresh data |
setResourceName(name) | Set resource name (e.g., 'users', 'users.tags') |
setFilterByTk(tk) | Set primary key filter (for single record get, etc.) |
runAction(actionName, options) | Call any resource action (e.g., create, update) |
on(event, callback) / off(event, callback) | Subscribe/unsubscribe to events (e.g., refresh, saved) |
MultiRecordResource Specific: getSelectedRows(), destroySelectedRows(), setPage(), next(), previous(), etc.
ctx.resource does not exist, it creates and binds one; if it already exists, it returns the existing instance. This ensures ctx.resource is available.ctx.resource. This is suitable for scenarios requiring multiple independent resources or temporary usage.undefined and requires ctx.initResource.ctx.resource?.refresh(), especially in scenarios like JSBlock where pre-binding might not exist.setResourceName(name) to specify the collection before loading data via refresh().ctx.resource