Manage the system setting values on a page
Creatio 8 Atlas uses the sdk.SysSettingsService
service to manage system settings.
To manage the value of a system setting:
-
Add a caption that displays the value of system setting on the page on step 1 of the Freedom UI page customization procedure if needed.
-
Set up how to manage the value of a system setting on the page on step 2 of the Freedom UI page customization procedure.
-
Enable the
sdk.SysSettingsService
system setting 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
viewModelConfig
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.- Instantiate the system value service from
@creatio-devkit/common
. - Load the system setting value and write it to the corresponding attribute.
- Implement the business logic that changes the system setting value and update the value of the corresponding attribute.
View an example of a
crt.HandleViewModelInitRequest
query handler withsomeVariable
calculation result written to theSomeAttributeName
attribute below.handlers schema sectionhandlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelInitRequest",
/* Custom implementation of a system query handler. */
handler: async (request, next) => {
/* Wait for the rest of the initialization handlers to finish. */
await next?.handle(request);
/* Instantiate a system setting service from @creatio-devkit/common. */
const sysSettingsService = new sdk.SysSettingsService();
/* Retrieve the value of the SomeSystemSetting system setting and write it to the SomeAttributeName attribute. */
const someVariable = await sysSettingsService.getByCode('SomeSystemSetting');
request.$context.SomeAttributeName = someConst.displayValue;
/* Calculate the value. */
...;
/* Update the result of someVariable calculation to the SomeAttributeName attribute. */
request.$context.SomeAttributeName = someVariable;
}
}
]/**SCHEMA_HANDLERS*/, - Instantiate the system value service from
-
Detailed example: Manage the system setting values on a page.