Skip to main content

Environment

The sdk.env object provides essential runtime information about the environment in which the custom function is being executed. This includes data about the authenticated user, the current tenant, locale, public settings, and more. It is especially useful for adapting UI or logic based on context, such as rendering user-specific content or localizing views.


Properties

PropertyTypeDescription
userobjectThe currently authenticated user object. May represent an agent.
userIdstringID of the authenticated user.
tenantobjectThe tenant in which the function is running.
currentReactiveVarA reactive version of the tenant object, updated dynamically.
currentSlugstringSlug identifier of the current tenant.
customAppInstanceIdstringID of the installed app instance if the function is running within an app.
customerUserobjectIf applicable, the customer-facing user object.
currentLocalestringThe currently active locale.
publicSettingsobjectShared environment settings across all tenants.

Example

CustomFunction(async function ({ sdk }, reject, resolve) {
resolve(async function CustomFunction({ sdk }) {
const currentUser = sdk.env.user
const tenantName = sdk.env.tenant?.payload?.name
const locale = sdk.env.currentLocale

sdk.options = function () {
return {
html: `<div>
<p>Welcome, ${currentUser?.profile?.firstname}!</p>
<p>Tenant: ${tenantName}</p>
<p>Locale: ${locale}</p>
</div>`
}
}
})
})

Notes

  • Use sdk.env.current.get() to access the latest reactive version of the tenant.
  • publicSettings can include flags or configurations defined globally.
  • Always null-check nested fields when rendering to avoid runtime errors.