Computed Attributes (computed attributes)
Computed attributes are additional fields whose values are not stored in the database but are generated dynamically based on other record attributes or arbitrary logic. They allow extending the data displayed in the journal without modifying the data model.
Computed attributes are defined in the journal configuration or in an individual column configuration, and can be used in column formatters and editors.
There are two main types of computed attributes:
Record Computed Attributes (R attributes) — attributes computed individually for each record;
Config Computed Attributes (C attributes) — attributes computed globally for the configuration.
Computed attributes can be defined at the journal level or for a specific column:
"computed": [
{
"id": "someAttribute",
"type": "script",
"config": {
"script": "return \"abcd\";"
}
}
]
To reference record attributes in the configuration, placeholders ${…} can be used. For example:
"computed": [
{
"id": "someAttribute",
"type": "script",
"config": {
"vars": {
"documentDisplayName": "${?disp}"
},
"script": "return \"abcd\" + vars.documentDisplayName;"
}
}
]
When placeholders ${…} are present in the configuration, the attribute automatically becomes an R attribute.
Computed attributes are available in the Formatter for column and Editor for column fields. Access is similar to record attribute access, but with the $computed prefix. For example:
"formatter": {
"type": "value",
"config": {
"value": "${$computed.someAttribute}"
}
},
"computed": [
{
"id": "someAttribute",
"type": "script",
"config": {
"vars": {
"documentDisplayName": "${?disp}"
},
"script": "return \"abcd\" + vars.documentDisplayName;"
}
}
]
Computed Attribute Types
Type |
Config |
Note |
|---|---|---|
script |
vars: Object<String, Any> — variables that will be available in the scriptscript: String — script text |
The following are available in the script context:
Records
_ — lodash library
vars — variables from the configuration
t — function for retrieving a localized message by key
|
value |
value: Any — valueMultiple values can be selected.
|