ctx.resource
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.
Applicable Scenarios
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.
Type Definition
- In contexts with pre-binding,
ctx.resourceis the corresponding resource instance. - In scenarios like JSBlock where there is no resource by default, it is
undefineduntilctx.initResource(type)is called.
Common Methods
Methods exposed by different resource types (MultiRecordResource, SingleRecordResource, APIResource, SQLResource) vary slightly. Below are the universal or commonly used methods:
MultiRecordResource Specific: getSelectedRows(), destroySelectedRows(), setPage(), next(), previous(), etc.
Examples
List Data (Requires initResource first)
Table Scenario (Pre-bound)
Single Record
Calling a Custom Action
Relationship with ctx.initResource / ctx.makeResource
- ctx.initResource(type): If
ctx.resourcedoes not exist, it creates and binds one; if it already exists, it returns the existing instance. This ensuresctx.resourceis available. - ctx.makeResource(type): Creates a new resource instance and returns it, but does not write it to
ctx.resource. This is suitable for scenarios requiring multiple independent resources or temporary usage. - ctx.resource: Accesses the resource already bound to the current context. Most blocks/pop-ups are pre-bound; otherwise, it is
undefinedand requiresctx.initResource.
Notes
- It is recommended to perform a null check before use:
ctx.resource?.refresh(), especially in scenarios like JSBlock where pre-binding might not exist. - After initialization, you must call
setResourceName(name)to specify the collection before loading data viarefresh(). - For the full API of each Resource type, see the links below.
Related
- ctx.initResource() - Initialize and bind a resource to the current context
- ctx.makeResource() - Create a new resource instance without binding it to
ctx.resource - MultiRecordResource - Multiple records/Lists
- SingleRecordResource - Single record
- APIResource - General API resource
- SQLResource - SQL query resource

