Script Module
The script module is automatically imported as script
.
Represents the currently running script. The script object includes the following:
_id
(ObjectId) the script identifieraccess
(Number) the acl level of access to the current in-context subjectarguments
(Object) the script arguments object. In triggers, there are old and new properties that represent the original and modifications made to the access context subject.depth
(Number) the 1-indexed script depth (a trigger firing trigger would have a depth of 2).label
(String) the script label.env
(Object) the current api environmenthost
(String) the api host (api.medable.com or api.dev.medable.com)name
(String) the environment name (production/development)url
(String) the api base endpoint (eg. https://api.medable.com/my_org/v2)version
(String) the current api version string
org
(CortexObject)_id
(ObjectId) the org identifiercode
(String) the org code
originalPrincipal
(ObjectId) The identifier of the principal who originally called the script. This may differ from the script principal if it was configured to run as a specific account.principal
(CortexObject)_id
(ObjectId) the identifier of the principal who called the script.email
(String) the principal's email addressname
(Object)first
(String) the principal's first namelast
(String) the principal's last name
roles
(ObjectId[]) a list of the principal's assigned org rolestz
(String) the timezone for the current principal. Defaults to org tz if no timezone is available for the principal.
type
(String) the script type (trigger, route, job)
Methods
as(principal, options, function) gc() getCalloutsRemaining() getElapsedTime() getMemoryFree() getMemoryUsed() getNotificationsRemaining() getOpsRemaining() getOpsUsed() getTimeLeft()
as(principal, options, function)
Calls function
as principal
. script.as()
calls can also be nested, and will always obey parent restrictions (excluding principal scope). Also available as a decorator (@as).
Arguments
principal
(String) The email or identifier of the new script principal.options
(Object) An options object that limits what's accessible insidefunction
.acl
(Object)safe
(Boolean=true) If true, automatically adds bypassCreateAcl, grant and skipAcl to acl.blacklistblacklist
(String[]=null) Adds blacklisted options to the current set, which are filtered out of all api calls. For example, addingskip
will causeorg.objects.accounts.find().skip(1).passthru()
to ignore the skip option.
principal
(Object)roles
(ObjectID[]=null) Adds roles to the current principal. To get an empty set of starting roles, call the script anonymously.scope
(String[]=null) Overrides the current principal scope. To use the same parent scope, it must be passed toscript.as()
.grant
(Number=0) Sets the grant level of the calling principal. This grant level will apply to all acl operations, including list and reference read/write-through, but not to nested calls toscript.as()
. Negates the need to use thegrant()
cursor modifier.skipAcl
(Boolean=false) If true, applies skipAcl (for list query results) to all acl operations, including list and reference read/write-through, but not to nested calls toscript.as()
. Negates the need to use theskipAcl()
cursor modifier.bypassCreateAcl
(Boolean=false) If true, applies bypassCreateAcl to all create operations, including list write-through, but not to nested calls toscript.as()
. Negates the need to use thebypassCreateAcl()
cursor modifier.
modules
(Object)safe
(Boolean=true) if true, adds a number of modules to the module blacklist (including api, cache, connections, console, debug, http, logger, notifications, objects.transfer, response, script, session).whitelist
(String[]=null) If set, these will be the only available api interfaces. If nestingscript.as()
, the parent module.whitelist is also evaluated.blacklist
(String[]=null) If set, these api interfaces will not be callable. If nestingscript.as()
, the parent module.blacklist is also evaluated.
function
(Function) The function to be called asprincipal
.
Returns
value
(Object) Returns the result of thefunction
argument.
gc()
Runs garbage collection and returns the number of bytes freed.
Returns
value
(Number)
getCalloutsRemaining()
Returns the number of http callouts (http module requests) available to the current running script. Check the Execution Limits in your org configuration for the maximum number of http callouts.
Returns
value
(Number)
getElapsedTime()
Returns the number of milliseconds since the start of the script.
Returns
value
(Number)
getMemoryFree()
Returns the number of bytes free for use in-script.
Returns
value
(Number)
getMemoryUsed()
Returns the number of bytes of memory currently allocated to the script.
Returns
value
(Number)
getNotificationsRemaining()
Returns the number of notifications.send() calls available to the current running script.
Returns
value
(Number)
getOpsRemaining()
Returns the number of byte code operations available to the script.
Returns
value
(Number)
getOpsUsed()
Returns the number of byte code operations consumed by the script.
Returns
value
(Number)
getTimeLeft()
Returns the number of milliseconds remaining to the script before a timeout error is triggered.
Returns
value
(Number)
script.as() example
Using @as decorator
Last updated