Display the value of a system variable
@creatio-devkit/common
includes the SysValuesService
service to manage system variables.
You can access system variables differently from the previous versions. To do this, write the system variable name in lowercase without _
delimiters and the CURRENT
prefix. Learn more: System variables list in Freedom UI.
Detailed example: Display the values of system variables on a page.
To display the value of a system variable on a page:
-
Add a label to display the value of a system variable if needed. Instructions: Set up a Label component (user documentation).
-
Add the dependencies. To do this, add
@creatio-devkit/common
library as a dependency. The library includes theSysValuesService
service to manage system variables.View an example that adds the
@creatio-devkit/common
library as a dependency to theSomeApp_FormPage
Freedom UI page schema below.AMD module dependencies/* Declare the AMD module. */
define("SomeApp_FormPage", /**SCHEMA_DEPS*/["@creatio-devkit/common"] /**SCHEMA_DEPS*/, function/**SCHEMA_ARGS*/(sdk)/**SCHEMA_ARGS*/ {
return {
...
}
}); -
Add an attribute. Instructions: Set up the field display condition (step 2).
-
Bind an attribute to the label. Instructions: Set up the field display condition (similarly to step 3). Instead of the
visible
property, use thecaption
property that handles the text displayed in the element. -
Implement the base request handler.
-
Go to the
handlers
schema section. -
Add a custom implementation of the
crt.HandleViewModelInitRequest
base request handler.- Create an instance of the system value service from
@creatio-devkit/common
. - Upload the system variable values.
- Handle the system variable value if needed.
- Specify data in the corresponding attribute.
- Create an instance of the system value service from
View an example of a
crt.HandleViewModelInitRequest
request handler that handles thesomeVariable
system variable and specifies the value in theSomeAttribute
attribute, below.handlers schema sectionhandlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelInitRequest",
/* Custom implementation of a system request handler. */
handler: async (request, next) => {
/* Create an instance of the system value service from "@creatio-devkit/common." */
const sysValuesService = new sdk.SysValuesService();
/* Upload the system variable values. */
const sysValues = await sysValuesService.loadSysValues();
/* handle the system variable value. */
const someVariable = sysValues.systemVariable;
...;
/* Specify the "someVariable" value of the system variable in the "SomeAttribute" attribute. */
request.$context.SomeAttribute = someVariable;
/* Call the next handler if it exists and return its result. */
return next?.handle(request);
}
}
]/**SCHEMA_HANDLERS*/, -