Environment
The sdk.env
object provides contextual data about the execution environment of a server-side function in GridStudio. It contains key information such as the active tenant, public settings, user metadata, and optionally, session or flow context.
This data allows server-side logic to adapt dynamically based on who is executing the function, in which tenant, and under what flow or session context.
Properties
Property | Type | Description |
---|---|---|
tenant | object | The current tenant in which the function is executing. |
customAppInstanceId | string | ID of the app instance, if the function belongs to a custom app. |
publicSettings | object | Public configuration settings shared across all tenants. |
user | object | The user (with default field selection) who triggered the function. |
session | object | The session object, if executed within a session context. |
customFlowInstance | object | The current flow instance, if part of a flow execution. |
💡 Some fields like
session
orcustomFlowInstance
are only available if their IDs are included in the function payload.
Example
CustomFunction(async function ({ sdk }, reject, resolve) {
const user = sdk.env.user
const tenant = sdk.env.tenant
const session = sdk.env.session
sdk.utils.logger.info({payload: {result: 'Triggered by:', user?.profile?.firstname}})
sdk.utils.logger.info({payload: {result: 'Tenant slug:', tenant.slug}})
sdk.utils.logger.info({payload: {result: 'Session ID:', session?._id}})
resolve()
})
Notes
- The environment is prepared asynchronously before your function runs.
- Only selected fields of the
user
document are exposed (for security and performance). - If
sessionId
orcustomFlowInstanceId
is included in the payload, they are resolved and included insdk.env
.