Set up the condition that populates a page field
To implement the example:
- Set up the page UI. Read more >>>
- Set up the condition that populates the field. Read more >>>
Set up the condition that populates the Description field on the custom request page. If the Name and Description field values match, populate the Description field using the new Name field value. Otherwise, leave the Description field value as is.
1. Set up the page UI
-
Create an app based on the Records & business processes template. Instructions: Create an app manually (user documentation).
For this example, create a Requests app.
-
Open the form page in the Freedom UI Designer.
For this example, open the Requests form page.
-
Add a field.
For this example, add the field that contains the request description. To do this:
-
Add a field of needed type to the working area of the Freedom UI Designer.
-
Click and fill out the field properties.
Element
Element type
Property
Property value
Field that contains the request description
Text
Title
Description
Code
UsrDescription
-
-
Save the changes.
2. Set up the condition that populates the field
Configure the business logic in the Client Module Designer. For this example, set up the condition that populates the field.
-
Open the source code of the Freedom UI page. To do this, click .
-
Implement the base request handler.
-
Go to the
handlers
schema section. -
Add a custom implementation of the
crt.HandleViewModelAttributeChangeRequest
base request handler.- Run the handler when the value of any attribute changes, including changes made after loading the attribute values from the data source.
- Check the
UsrName
attribute value. - Save the
UsrDescription
attribute value to theisFieldsShouldBeSynchronized
constant. - Check the
UsrDescription
attribute value. If the value matches theUsrName
attribute value, set theUsrDescription
attribute to the same value as the newUsrName
attribute value. Otherwise, theUsrDescription
attribute value remains unchanged.
handlers schema sectionhandlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelAttributeChangeRequest",
/* The custom implementation of the system request handler. */
handler: async (request, next) => {
/* Check the request name. */
if (request.attributeName === 'UsrName') {
const isFieldsShouldBeSynchronized = request.oldValue === await request.$context.UsrDescription;
/* Check the request description. */
if (isFieldsShouldBeSynchronized) {
/* If the "UsrDescription" attribute value matches the "UsrName" attribute value, set the "UsrDescription" attribute to the same value as the new "UsrName" attribute value. */
request.$context.UsrDescription = await request.$context.UsrName;
}
}
/* Call the next handler if it exists and return its result. */
return next?.handle(request);
}
}
]/**SCHEMA_HANDLERS*/, -
-
Save the changes.
View the result
- Open the Requests section.
- Create a request that has an arbitrary name. For example, "Vacation."
- Change the request description to an arbitrary value. For example, "Paid vacation."
- Change the request name to an arbitrary value. For example, "Day off."
As a result:
- Creatio will populate the Description field for requests whose previous values of the Name and Description fields match.
- Creatio will leave the Description field as is for requests whose previous values of the Name and Description fields differ. View the result >>>
Source code
/* Declare the AMD module. */
define("UsrRequests_FormPage", /**SCHEMA_DEPS*/[]/**SCHEMA_DEPS*/, function/**SCHEMA_ARGS*/()/**SCHEMA_ARGS*/ {
return {
viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[
{
"operation": "merge",
"name": "Feed",
"values": {
"dataSourceName": "PDS",
"entitySchemaName": "UsrRequests"
}
},
{
"operation": "merge",
"name": "AttachmentList",
"values": {
"columns": [
{
"id": "fc0f31d6-4d27-42db-95bf-869d0b268238",
"code": "AttachmentListDS_Name",
"caption": "#ResourceString(AttachmentListDS_Name)#",
"dataValueType": 28,
"width": 200
}
]
}
},
{
"operation": "insert",
"name": "UsrName",
"values": {
"layoutConfig": {
"column": 1,
"row": 1,
"colSpan": 1,
"rowSpan": 1
},
"type": "crt.Input",
"label": "$Resources.Strings.UsrName",
"control": "$UsrName",
"labelPosition": "auto"
},
"parentName": "SideAreaProfileContainer",
"propertyName": "items",
"index": 0
},
/* Field that contains the request description. */
{
"operation": "insert",
"name": "UsrDescription",
"values": {
"layoutConfig": {
"column": 1,
"row": 2,
"colSpan": 1,
"rowSpan": 1
},
"type": "crt.Input",
"label": "$Resources.Strings.UsrDescription",
"labelPosition": "auto",
"control": "$UsrDescription",
"multiline": false
},
"parentName": "SideAreaProfileContainer",
"propertyName": "items",
"index": 1
}
]/**SCHEMA_VIEW_CONFIG_DIFF*/,
viewModelConfigDiff: /**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/[
{
"operation": "merge",
"path": [
"attributes"
],
"values": {
"UsrName": {
"modelConfig": {
"path": "PDS.UsrName"
}
},
"UsrDescription": {
"modelConfig": {
"path": "PDS.UsrDescription"
}
}
}
},
{
"operation": "merge",
"path": [
"attributes",
"Id",
"modelConfig"
],
"values": {
"path": "PDS.Id"
}
}
]/**SCHEMA_VIEW_MODEL_CONFIG_DIFF*/,
modelConfigDiff: /**SCHEMA_MODEL_CONFIG_DIFF*/[
{
"operation": "merge",
"path": [],
"values": {
"primaryDataSourceName": "PDS"
}
},
{
"operation": "merge",
"path": [
"dataSources"
],
"values": {
"PDS": {
"type": "crt.EntityDataSource",
"config": {
"entitySchemaName": "UsrRequests"
},
"scope": "page"
}
}
}
]/**SCHEMA_MODEL_CONFIG_DIFF*/,
handlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.HandleViewModelAttributeChangeRequest",
/* The custom implementation of the system request handler. */
handler: async (request, next) => {
/* Check the request name. */
if (request.attributeName === 'UsrName') {
const isFieldsShouldBeSynchronized = request.oldValue === await request.$context.UsrDescription;
/* Check the request description. */
if (isFieldsShouldBeSynchronized) {
/* If the "UsrDescription" attribute value matches the "UsrName" attribute value, set the "UsrDescription" attribute to the same value as the new "UsrName" attribute value. */
request.$context.UsrDescription = await request.$context.UsrName;
}
}
/* Call the next handler if it exists and return its result. */
return next?.handle(request);
}
}
]/**SCHEMA_HANDLERS*/,
converters: /**SCHEMA_CONVERTERS*/{}/**SCHEMA_CONVERTERS*/,
validators: /**SCHEMA_VALIDATORS*/{}/**SCHEMA_VALIDATORS*/
};
});