Display the value of a system variable
Creatio 8 Atlas uses the sdk.SysValuesService
service to manage system variables.
In Creatio 8 Atlas, you can access system variables differently from the previous versions. In this version, write the system variable name in lowercase without _
delimiters and the CURRENT
prefix. View the complete list of system variables in a separate article: System variables list in Freedom UI.
To display the value of a system variable on a page:
-
Add a page inscription to display the values of system variables on step 1 of the Freedom UI page customization procedure if needed.
-
Set up how to display the value of a system variable on the page on step 2 of the Freedom UI page customization procedure.
-
Enable the
sdk.SysValuesService
system variable service. To do this, add the@creatio-devkit/common
dependency to the AMD module.View an example that adds a dependency to the
UsrAppClientSchemaName
AMD module below.AMD module dependencies/* AMD module declaration. */
define("UsrAppClientSchemaName", /**SCHEMA_DEPS*/["@creatio-devkit/common"] /**SCHEMA_DEPS*/, function/**SCHEMA_ARGS*/(sdk)/**SCHEMA_ARGS*/ {
return {
...
};
}); -
Add an attribute that stores data to the
viewModelConfigDiff
schema section. Add the attribute similarly to the procedure for setting up the field display condition. -
Bind the
caption
property to the corresponding model attribute in theviewConfigDiff
schema section. Bind the property similarly to the setup procedure for the field display condition. Instead of thevisible
property, use thecaption
property that displays the text in the element. -
Add a custom implementation of the
crt.HandlerViewModelInitRequest
system query handler to thehandlers
schema section. The handler is executed when theView
model is initialized. Depending on the value of the attribute (true
orfalse
), the handler executes different business logic.- Instantiate the system value service from
@creatio-devkit/common
. - Load system values.
- Calculate the value and write the calculation result to the corresponding attribute if needed.
View an example of a
crt.HandlerViewModelInitRequest
query handler withsomeVariable
calculation result written in theSomeAttributeName
attribute below.handlers schema sectionhandlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelInitRequest",
/* Custom implementation of a system query handler. */
handler: async (request, next) => {
/* Instantiate the system value service from @creatio-devkit/common. */
const sysValuesService = new sdk.SysValuesService();
/* Load system values. */
const sysValues = await sysValuesService.loadSysValues();
/* Calculate the value. */
const someVariable = sysValues.systemVariable;
...;
/* Write the result of someVariable calculation to the SomeAttributeName attribute. */
request.$context.SomeAttributeName = someVariable;
/* Call the next handler if it exists and return its result. */
return next?.handle(request);
}
}
]/**SCHEMA_HANDLERS*/, - Instantiate the system value service from
-
Detailed example: Display the values of system variables on a page.