Implement a custom converter using remote module
To implement the example:
- Create an Angular project. Read more >>>
- Install
npmpackages. Read more >>> - Create a custom converter. Read more >>>
- Add the converter to the Freedom UI page. Read more >>>
Add a custom converter to the custom request page. The converter adds the "is the request name" string to the Name field value. Display the converted value as a Label component. Implement the synchronous converter using a remote module created in Angular framework.
1. Create an Angular project
To create an Angular project, follow the instructions: Create an Angular project.
For this example:
<%projectName%>macro is set to "sdk_custom_converter."<%vendorPrefix%>macro is set to "usr."
As a result, an Angular project to develop a custom converter using a remote module will be added. The project contains:
- A
RemoteEntryDefinitionobject exported from the "src/main.ts" file. - The runtime feature files used to implement converter.
- The optional design feature files.
- The "sdk_custom_converter-runtime" runtime feature ID.
2. Install npm packages
To install npm packages, follow the instructions: Install npm packages.
As a result, required npm packages are installed.
3. Create a custom converter
-
Ensure the project includes the "AGENTS.md" file. Instructions: Create a custom Freedom UI component (step 1).
-
Run the
ng g class features/runtime/converters/concat.convertercommand in the Visual Studio Code terminal to create an Angular class in the project. This adds theConcatConverterclass files to the "src/app/features/runtime/converters" project directory. -
Specify that the
ConcatConverterclass is a converter.- Open the "concat.converter.ts" file.
- Implement the
Converter<string, string>interface from the@creatio-devkit/commonlibrary in theConcatConverterclass. - Flag the
ConcatConverterclass using the@CrtConverterdecorator. - Import the required functionality from the libraries into the class.
- Save the file.
"concat.converter.ts" file/* Import the required functionality from the libraries. */import { Converter, CrtConverter } from "@creatio-devkit/common";/* Add the CrtConverter decorator to the ConcatConverter class. */@CrtConverter({type: 'usr.ConcatConverter',})export class ConcatConverter implements Converter<string, string> {} -
Inject dependencies.
- Open the "concat.converter.ts" file.
- Create the
CONCAT_SEPARATOR_TOKENinjection token using theInjectionTokenclass. Use the token to work with Angular DI (dependency injection). - Inject the dependency into the constructor of the
ConcatConverterclass using the@CrtInjectdecorator. - Import the required functionality from the libraries into the class.
- Save the file.
"concat.converter.ts" file/* Import the required functionality from the libraries. */import { InjectionToken } from "@angular/core";import { Converter, CrtInject } from "@creatio-devkit/common";/* The CONCAT_SEPARATOR_TOKEN token that works with Angular DI (dependency injection). */export const CONCAT_SEPARATOR_TOKEN =new InjectionToken<string>('CONCAT_SEPARATOR_TOKEN');export class ConcatConverter implements Converter<string, string> {/* Inject the dependency using the @CrtInject decorator. */constructor(@CrtInject(CONCAT_SEPARATOR_TOKEN) private _separator: string) { }} -
Register the
ConcatConverterconverter and theCONCAT_SEPARATOR_TOKENtoken. The template already contains the runtime feature activation andbootstrapCrtModule()call. Extend the existing runtime feature files to register the converter.-
Open the "runtime-feature.module.ts" file.
-
Add the
ConcatConverterconverter to theconverterssection in the@CrtModuledecorator. -
Add the configuration object to the
providerssection in the@NgModuledecorator.- Set the
provideproperty to "CONCAT_SEPARATOR_TOKEN." - Set the
useValueproperty to ' ' (a single space).
"runtime-feature.module.ts" file/* Import the required functionality from the libraries. */import { ApplicationRef, DoBootstrap, NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { CrtModule } from '@creatio-devkit/common';import {ConcatConverter,CONCAT_SEPARATOR_TOKEN} from './converters/concat.converter';@CrtModule({/* Specify that ConcatConverter is a converter. */converters: [ConcatConverter],})@NgModule({declarations: [],imports: [BrowserModule],providers: [{provide: CONCAT_SEPARATOR_TOKEN,useValue: ' ',},],})export class RuntimeFeatureModule implements DoBootstrap {ngDoBootstrap(_appRef: ApplicationRef): void {}} - Set the
-
Open the "runtime.feature-definition.ts" file.
-
Add the public
typeproperty of the converter to thediscovery.converterssection."runtime.feature-definition.ts" file/* Import the required functionality from the libraries. */import type {RemoteDesignerDefinitionsLoadContext,RemoteFeatureDefinition} from '@creatio-devkit/common';/*** Root definition for the runtime feature.** Describes the view elements this remote package contributes at runtime* and provides the entry points used to load designer metadata and activate* the feature.*/export const runtimeFeatureDefinition = {id: 'sdk_custom_converter-runtime',discovery: {viewElements: [],converters: [{type: 'usr.ConcatConverter',},],},loadDesignerDefinitions: (context: RemoteDesignerDefinitionsLoadContext) =>import('./runtime.designer-definitions').then((m) => m.loadRuntimeDesignerDefinitions(context)),activate: () =>import('./runtime.feature-activation').then((m) => m.activateRuntimeFeature()),} satisfies RemoteFeatureDefinition; -
Import the required functionality from the libraries into the files.
-
Save the files.
-
-
Implement the conversion of an incoming value.
- Open the "concat.converter.ts" file.
- Implement the
convert(value: string, context: ViewModelContext, ...params: string[]): string;method of theConcatConverterinterface. - Import the required functionality from the libraries into the class.
- Save the file.
"concat.converter.ts" file/* Import the required functionality from the libraries. */import { Converter, ViewModelContext } from "@creatio-devkit/common";export class ConcatConverter implements Converter<string, string> {/* Implement the convert() method. */public convert(value: string,context: ViewModelContext,...params: string[]): string {return [value, ...params].join(this._separator);}} -
Run the
npm run buildcommand in the Visual Studio Code terminal to build the project.
As a result, the build will be added to the "dist" directory of the Angular project. The build will have the "sdk_custom_converter" name.
4. Add the converter to the Freedom UI page
-
Repeat steps 1-4 of the instructions: Add the custom Freedom UI component to the Freedom UI page. For this example, create a Requests app.
-
Add a label of the request prefix.
-
Drag the Label component to the canvas.
-
Fill out the component parameters.
Parameter
Value
Style
Body
Text color
#757575 Element code
UsrRequestPrefix
-
-
Click
→ Source code to open the source code of the Freedom UI page. -
Bind the converter to the label.
- Go to the
viewConfigDiffschema section →UsrRequestPrefixelement. - Add a
UsrNameattribute to thecaptionproperty. - Bind the
usr.ConcatConverter :'is the request name'converter to the$UsrNameattribute in thecaptionproperty.
viewConfigDiff schema sectionviewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[{"operation": "insert","name": "Label","values": {/* Apply the usr.ConcatConverter converter to the $UsrName attribute. */"caption": "$UsrName | usr.ConcatConverter :'is the request name'",},}]/**SCHEMA_VIEW_CONFIG_DIFF*/, - Go to the
-
Click Save.
As a result, the custom converter will be added to the request page.
View the result
- Open the Requests section.
- Create a request that has an arbitrary name. For example, "Vacation."
As a result, Creatio will add the "is the request name" string to the request name. The synchronous converter is implemented using a remote module created in the Angular framework.