Skip to main content

Server-side globals

When action logic runs on the C# backend via Jint, several global objects are injected into the JavaScript execution context. These are available in any server-side action handler - see Actions for how to define them.

All types are declared in api/typings/cmw-server.ts.

Record context

These globals provide access to the record(s) being processed. They are always available.

GlobalTypeDescription
entitymutable recordThe current record being processed. Changes to this object are persisted.
entityOldread-only recordThe previous state of the record, before the current action.
recordsarrayArray of records when processing bulk operations.

currentUser

Identity and role information for the user who triggered the action. Typed as CurrentUserServer.

MemberDescription
.idUser ID
.emailEmail address
.nameDisplay name
.timeZoneUser's timezone
.companyIdCompany ID
.isGlobalAdminWhether the user is a global admin
.isWorkspaceAdminWhether the user is an admin of the current workspace
.isInGroup(groupIdOrName)Check membership in a specific group
.isInAnyOfGroups(groups)Check membership in any of the given groups
.isInField(fieldName, entity?)Check if the user appears in a people field on the record
.isDefaultUnAuthUser()Returns true for unauthenticated users
.isWorkspaceAdminOf(workspaceId)Check admin role in a different workspace

ComindServer

The main platform API for server-side logic.

Record queries

MethodDescription
.queryApp(wksApp, relex, fields?)Fetch a single record matching a relex expression
.queryAppRecords(wksApp, relex, fields?, sortBy?)Fetch multiple records. Also accepts a params object with limitRecords, skipRecords, and other options.
.queryAppCached(...)Cached variant of .queryApp()
.queryAppRecordsCached(...)Cached variant of .queryAppRecords()

Record mutations

MethodDescription
.createAppRecord(appAlias, data, runAsUser?)Create a record. Optional runAsUser for impersonation.
.updateAppRecord(id, transition, values, runAsUser?)Update a record by executing an action on it
.deleteAppRecord(id, runAsUser?)Delete a record
.bulkCreateAppRecords(wksApp, dataList)Create multiple records in one call
.bulkDeleteAppRecords(ids)Delete multiple records in one call
.importData({data, keyFields, ...})Import data with full options - duplicate handling, field mapping, etc.

Utilities

MethodDescription
.AclsPermission helpers: .workspaceAdmin, .workspaceTeam, .group(name), .user(id)
.actionName of the currently executing action
.sleep(ms)Pause execution for the given number of milliseconds
.resolveLookup(fieldName)Resolve a lookup field's display caption
.matchLookup(fieldName, captionValue)Find a lookup ID by its caption text
.generateUniqueIdForPrefix(prefix)Generate an auto-numbered ID with the given prefix
.getAccessPass(...)Obtain an impersonation access token
.htmlToText(html)Strip HTML tags and return plain text

RestApi

HTTP client for calling external services. Typed as RestApiServer.

Typical usage:

RestApi.createClient('https://api.example.com');
RestApi.createRequest('/endpoint', 'POST');
RestApi.addHeader('Authorization', 'Bearer ...');
RestApi.addJsonBody({ key: 'value' });
const result = RestApi.executeRequest();
MethodDescription
.createClient(baseUrl)Initialize a client with a base URL
.createRequest(path, method)Set up a request
.addHeader(name, value)Add a request header
.addJsonBody(body)Attach a JSON body
.executeRequest()Send the request and return the response
.setHttpBasicAuth(...)Use HTTP Basic authentication
.setOAuth2AuthorizationHeaderAuth(...)Use OAuth 2 bearer token authentication
.addFile(...)Attach a file to the request
.downloadFile(...)Download a file from the response
.setRequestTimeout(seconds)Set a timeout in seconds

Files

File operations - reading, writing, and converting files. Typed as FilesServer.

MethodDescription
.getFileRef(fileRecordId)Get a file reference from a file record ID
.persistFileRef(ref)Save a temporary file reference permanently
.readExcelFileRef(ref, rows, skip?, sheet?)Read rows from an Excel file
.writeExcelFileRef({sourceRef, updateCells, ...})Write or modify an Excel file
.readCsvFileRef(ref, rows, skip?)Read rows from a CSV file
.writeCsvFileRef({rows, delimiter?})Write a CSV file
.writePdfFileRef({html})Generate a PDF from an HTML string
.mergePdfFileRefs(refs)Merge multiple PDF files into one
.zipFileRefs(refs)Create a ZIP archive from file references
.readFileRefAsBase64(ref)Read a file's contents as a base64 string
.useBase64DataAsFileRef(base64)Create a file reference from base64 data

AppSchema

App installation and configuration. Typed as AppSchemaServer. See Settings model for how app variables and secrets are defined.

MethodDescription
.install({appId, position?, wksAlias?})Install an app into a workspace
.uninstall({appId, wksAlias})Remove an app from a workspace
.load({appId})Load an app's schema definition
.getVars()Get app variables defined in settings
.getSecrets()Get app secrets from COMIND_SECRET_* environment variables
.getWorkspaceAdmins()List workspace admin user IDs

Utils

General-purpose utilities. Typed as UtilsServer.

MethodDescription
.formatString(template, obj?)Format a string with interpolation
.formatDateTime(date, format)Format a date using a format string
.formatNumber(number, format)Format a number using a format string
.getDatesDiff(date1, date2)Get the time span between two dates
.generateGuid()Generate a UUID
.generateSha256(data)Generate a SHA-256 hash
.generateMd5(data)Generate an MD5 hash
.parseJwt(jwt)Parse a JWT token and return its payload
.dateTimeToAnotherTimeZone(dt, targetTz)Convert a datetime to a different timezone
.writeCsvString(data, delimiter?)Serialize data to a CSV string
.parseCsvString(csv, delimiter?)Parse a CSV string into structured data

console

Logging interface for debugging server-side logic. Typed as ConsoleServer.

MethodDescription
.log()General log output
.debug()Debug-level output
.info()Informational output
.warn()Warning output
.error()Error output
.profile() / .profileEnd()Start and stop a performance timer

Additional globals

These globals are available for specialized use cases.

GlobalDescription
parserHTML parser for processing markup
JsRequireDynamic module loading within server-side scripts
LiquidParserLiquid template parsing and rendering
runContextExecution context with .invokedTransition - the action identifier that triggered the current run