Manage the system setting values
@creatio-devkit/common
includes the SysSettingsService
service to manage system settings.
Detailed example: Manage the system setting values on a page.
To manage the value of a system setting:
-
If needed, add a label to display the value of a system setting. Instructions: Set up a Label component (user documentation).
-
Add the dependencies. Instructions: Display the value of a system variable (similarly to step 2). Instead of the
SysValuesService
service, use theSysSettingsService
service that manages system settings. -
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.HandleViewModelResumeRequest
base request handler.- Create an instance of the system setting service from
@creatio-devkit/common
. - Retrieve the value of the system setting and specify data in the corresponded attribute.
- Implement the business logic that changes the system setting value.
- Specify data in the corresponding attribute.
- Create an instance of the system setting service from
View an example of a
crt.HandleViewModelResumeRequest
request handler that changes thesomeSystemSetting
system setting and specifies the value in theSomeAttribute
attribute, below.handlers schema sectionhandlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelResumeRequest",
/* The custom implementation of the system request handler. */
handler: async (request, next) => {
/* Wait for the rest of the initialization handlers to finish. */
await next?.handle(request);
/* Create an instance of the system setting service from "@creatio-devkit/common." */
const sysSettingsService = new sdk.SysSettingsService();
/* Retrieve the value of the "SomeSystemSetting" system setting. */
const someVariable = await sysSettingsService.getByCode('SomeSystemSetting');
/* Specify the value of the system setting in the "SomeAttribute" attribute. */
request.$context.SomeAttribute = someConst.displayValue;
/* Implement the business logic that changes the system setting value. */
...;
/* Specify the new value of the system setting in the "SomeAttribute" attribute. */
request.$context.SomeAttribute = someVariable;
}
}
]/**SCHEMA_HANDLERS*/, -
See also
Set up a Label component (user documentation)