context
Object in Formulas
The context
contain additional information about the context we're running in.
app
- contains information about the current app new 13.07appId
zoneId
isContent
isSite
isGlobal
cache
- an object which is only for this function and will be persisted across calls - use it to save temporary valuesdebug
- a true/false toggle if the form is in develop/debug mode - Use this to show/hide really advanced fields. new in 12.02target
- everything about the target of the formula - the current fieldtype
= What the function processesField.Value
orField.Settings
(Future:Form.Variable
etc.)name
- field name or setting-name, soFirstName
orVisible
entity
id
- the id of the entity - 0 if it's newguid
- the GUID of the entity, always providedtype
- entity type informationguid
name
culture
code
name
- this will returnundefined
scenarios where no languages are activated
features
new v13.10isEnabled('FeatureName')
- will return true if this feature is enabled.
Important: only admins users will know about all available features, non-admins will only have a subset marked as public.
form
new v13.10(deprecated in v2) - will run all formulas in the current form. This is typically meant for use in fetch-promises after the data returned and was put in the cache new 13.07runFormulas()
user
new in v13.11email
new v16.00guid
new v16.00id
user id or-1
if anonymousisAnonymous
-true
if the user is not logged inisContentAdmin
new v16.00isSiteAdmin
isSystemAdmin
name
new v16.00username
new v16.00
experimental
- this is for internal APIs we're testing, they are not public. You can use them, but expect the APIs to change in near future
Using the context.cache
In some cases you may want to remember a result of intermediate work. For this you can use the context.cache
object. A simple exammple would be if you only want to run something once, in which case you could write something like this
v1(data, context) {
// don't do anything on following runs / return existing value
if(context.cache.notFirstRun) return data.value;
context.cache.notFirstRun = true;
return true;
}
History
- Introduced in 2sxc 12.01
- Added
context.features.isEnabled('FeatureName')
in v13.10 - Added
context.features.get('FeatureName')
in v13.10 - Added
context.app
in v13.10 - Added
context.user
in v13.11 - Added
context.form.runFormulas()
in v13.11
Shortlink to here: https://go.2sxc.org/js-fcontext